Infix expression into the postfix expression, Data Structure & Algorithms

Q. Write down an algorithm to convert an infix expression into the postfix expression.    

Ans.

Algorithm to convert infix expression to post fix expression is given as follows.

1. opstk = the empty stack;

2. while (not end of input) {

3. symb = next input character;

4. if (symb is an operand) add symb to postfix string

5. else {

6. while (!empty (opstk) and prcd (top (opstk), symb)>0){

7. topsymb = pop(opstk);

8. add topsymb to the postfix string; }/*end while*/

9. if (empty (opstk) || symb! = ')' ) push (opstk, symb); else /*pop the open parenthesis and discard it */

topsymb = pop(opstk);

} /* end else */

}/* end while */

/* output any remaining operator */

10.while (!empty (opstk)){

11. top symb = pop (opstk);

12. add topsymb to the postfix string;

} /* end while * /

/*output any remaining operator*/

Posted Date: 7/13/2012 2:05:04 AM | Location : United States







Related Discussions:- Infix expression into the postfix expression, Assignment Help, Ask Question on Infix expression into the postfix expression, Get Answer, Expert's Help, Infix expression into the postfix expression Discussions

Write discussion on Infix expression into the postfix expression
Your posts are moderated
Related Questions

Row Major Representation In memory the primary method of representing two-dimensional array is the row major representation. Under this representation, the primary row of the a

Operations on B-Trees Given are various operations which can be performed on B-Trees: Search Create Insert B-Tree does effort to minimize disk access and t

Write an algorithm for compound interest.

how we can convert a graph into tree

Which sorting algorithms does not have a worst case running time of  O (n 2 ) ? Merge sort

After learning this, you will be able to: understand the concept of algorithm; understand mathematical foundation underlying the analysis of algorithm; to understand se

how to implement multiple stack using single dimension array in c

When writing a code for a program that basically answers Relative Velocity questions how do you go at it? How many conditions should you go through?

Suppose you are given the results of 5 games of rock-paper-scissors. The results are given to you on separate pieces of paper; each piece says either 'A' if the first person won, o