Coders Packet

Application of stack infix to postfix. Using C++ programming language

By Srivenurajulu G

Application of stack infix to postfix which follows last in first out and it is a linear data structure. Using C++ programming language

Algorithm

  1. Push ‘(‘ to the stack.
  2. Scan the infix expression from left to right and repeat steps 3 to 6 for each element until the stack is empty.
  3. If an operand is encountered, add it to the postfix expression.
  4. If a left parenthesis is encountered, then push it into the stack.
  5. If an operator is encountered, then:

(a) Repeatedly pop all the operators from the stack which have the same or higher precedence than the operator that is being encountered and add it to the postfix expression.

(b) Push the operator to the stack. If the right parenthesis is encountered, then:

6.

(a) Repeatedly pop operators from the stack and add them to the postfix expression until a left parenthesis is encountered.

(b) Remove the left parenthesis and pop it.

  1. Stop. 

For Example:

It follows stack evaluation the pop operation is done and the element is deleted from the top of the stack

Likewise the example a follows

The expression is   (a*b+c)

Converted Expression is ab*c+

Download project

Reviews Report

Submitted by Srivenurajulu G (Srivenurajulu)

Download packets of source code on Coders Packet