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
Which of the three is not a popular cloud suite or online office suite?
SIZIF [17.4K]
C. Thinksmart - thinksmart only sells products and softwares of their own. Thinksmart is a online selling company that sells moslty softwares on their domain. Think smart is not a popular cloud suite or an online office suite. So the answer to your question is C.
3 0
4 years ago
Which of these is a benefit of using the Sort option?​
Reika [66]

There are many benefits of using the shot options in Excel. Some benefits are allowing you to short by number,date,color, letter, columns,or text. This benefits the user because it allows the user to bring data up more easily.

I hope this answers is helpful

3 0
3 years ago
Read the following code: x = currentWeight print(x - 20) What value will this code calculate?
Serga [27]

D because weight print = x and -20 is the pound loss.

5 0
3 years ago
Search online for the various configuration processors available. Mention the brand names that are widely used.
Zina [86]

Answer:

Intel Pentium 4

And some others

Explanation:

3 0
3 years ago
Read 2 more answers
You must install JMP pro on your computer before attempting this assignment. You must use the data file: MedicalMalpractice.JMP.
Arte-miy333 [17]

Answer:

Mean = 91044.915

Median = 22750

Explanation:

See exhibit 1 in attachment for explanation.

6 0
4 years ago
Other questions:
  • Jim has entered the age of each of his classmates in cells A1 through A65 of a spreadsheet. Which function should Jim use to fin
    11·2 answers
  • Identify the parts used in an electric circuit- Tiles
    9·2 answers
  • A cyberbully is someone who invades another person’s privacy by
    13·2 answers
  • If a user copies the formula D15 into D16, what would the formula read in D16?
    15·2 answers
  • Write a function called median, that takes as parameter a full, sorted array of doubles and returns the median of the list. For
    15·1 answer
  • Someone plzzzzz help me!!!
    6·1 answer
  • How do i build a supercomputer.?
    11·1 answer
  • Which programming language represents data in the form of a series of zeros and ones​
    7·1 answer
  • Why is time zone an important factor affecting when communicating
    14·1 answer
  • QN, 3. Write the working principle of computer.<br>​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!