1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
labwork [276]
3 years ago
9

Convert infix to postfix

Computers and Technology
1 answer:
kvv77 [185]3 years ago
4 0

Answer:

static int checkSymbol(char ch)

{

switch (ch)

{

case '+':

case '-':

return 1;

case '*':

case '/':

return 2;

case '^':

return 3;

}

return -1;

}

static String convertInfixToPostfix(String expression)

{

String calculation = new String("");

Stack<Character> operands = new Stack<>();

Stack<Character> operators = new Stack<>();

 

for (int i = 0; i<expression.length(); ++i)

{

char c = expression.charAt(i);

if (Character.isLetterOrDigit(c))

operands.push(c);

else if (c == '(')

operators.push(c);

 

else if (c == ')')

{

while (!operators.isEmpty() && operators.peek() != '(')

operands.push(operators.pop());

 

if (!operators.isEmpty() && operators.peek() != '(')

return NULL;    

else

operators.pop();

}

else

{

while (!operators.isEmpty() && checkSymbol(c) <= checkSymbol(operators.peek()))

operands.push(operators.pop());

operators.push(c);

}

}

while (!operators.isEmpty())

operands.push(operators.pop());

while (!operands.isEmpty())

calculation+=operands.pop();

calculation=calculation.reverse();

return calculation;

}

Explanation:

  • Create the checkSymbol function to see what symbol is being passed to the stack.
  • Create the convertInfixToPostfix function that keeps track of the operands and the operators stack.
  • Use conditional statements to check whether the character being passed is a letter, digit, symbol or a bracket.
  • While the operators is  not empty, keep pushing the character to the operators stack.
  • At last reverse and return the calculation which has all the results.
You might be interested in
What device brocasts all data packets to other nodes on a network?
katovenus [111]
Switch/Router is Broadcast 
8 0
3 years ago
Microsoft word 2010 lab 6-1
icang [17]

Answer:

I ain't ever seen 2 pretty bestfriends, its always one of them that gotta be ugly  

Explanation:

5 0
3 years ago
Read 2 more answers
Apple was a pioneer in user interface development, introducing the _____, complete with mouse and screen icons, in the early 198
KiRa [710]

Answer:

The answer is "Option b"

Explanation:

The graphical UI is a kind of user interface, which is used in apple technology. It enables the consumers to use graphic symbols and the main symbol sound signal to communicate with electronic devices rather of text-based consumer interface, type tag commands or code navigation, and wrong option can be described as follows:

  • Option a and Option c both were wrong because the command-line interface is a text-based program, and binary line access via command line.
  • In option d, It is a text-based command, that is used to intact with the user, that's why it is wrong.
7 0
3 years ago
What is an efficient way to ensure that the code is working as per the acceptance criteria/business requirements? (1 correct ans
seraphim [82]

Answer:

1. through automated functional tests

Explanation:

5 0
3 years ago
Read 2 more answers
WHAT ACTIONS CAUSE SPAM ON LINKEDIN?
klio [65]

Answer:

LinkedIn has a very smart algorithm, and it has a very strict policy against spammers. Back in 2014, it deleted millions of accounts that were causing spam on LinkedIn.  

Spam occurs:  

1. When you send bulk of connect requests in a short time  

2. When you send irrelevant messages to prospects  

3. When you Perform overactivity  

4. When you use LinkedIn automation tools  

5. When you send spammy and sales-y messages  

All these actions cause spam on LinkedIn, and it immediately takes action against you by restricting your account temporarily or permanently.

4 0
3 years ago
Other questions:
  • When you right-click certain areas of the Word or other Office app windows, a command menu will appear. Group of answer choices
    13·1 answer
  • How is the EF​ computed? A. ES​ + Activity time B. LF minusActivity time C. ​Min{LS of all immediate following​ activities} D. ​
    11·1 answer
  • PLEASE HELP FAST !!!!!!!!!!
    12·1 answer
  • “identify the skill in the following scenario” :
    6·2 answers
  • What area displays the title of the document
    14·1 answer
  • If you entered data into row 4 and it should be in row 3, you should _____.
    8·2 answers
  • What is the best stratiget to avoid paying intrest in your credit cared
    13·1 answer
  • Describe the major elements and issues with system prototyping​
    7·1 answer
  • ProgrammingAssignment3
    8·1 answer
  • Personal statements School leaver
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!