Infix to Postfix

  1. Create an empty stack called op_stack for keeping operators. Create an empty list for output.
  2. onvert the input infix string to a list by using the string method split.
  3. Scan the token list from left to right.
  4. When the input expression has been completely processed, check the op_stack. Any operators still on the stack can be removed and appended to the end of the output list.

Stack processing

  1. Create an empty stack called operand_stack.
  2. Convert the string to a list by using the string method split.
  3. Scan the token list from left to right.
  4. If the token is an operand, convert it from a string to an integer and push the value onto the operand_stack.
  5. If the token is an operator, *, /, +, or −, it will need two operands. Pop the operand_stack twice. The first pop is the second operand and the second pop is the first operand. Perform the arithmetic operation. Push the result back on the operand_stack.
  6. When the input expression has been completely processed, the result is on the stack. Pop the operand_stack and return the value.

© Problem Solving with Algorithms and Data Structures