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
Double ended queues are implemented along doubly linked lists. A doubly link list can traverse in both of the directions as it contain two pointers namely left pointers and righ

Write an algorithm for binary search. Algorithm for Binary Search 1.  if (low> high) 2.  return (-1) 3.  Mid = (low + high)/2 4.  if ( X = = a[mid]) 5.  return (mid); 6.

Draw a flowchart of a Booth''s multiplication algorithm and explain it.

Big oh notation (O) : The upper bound for the function 'f' is given by the big oh notation (O). Considering 'g' to be a function from the non-negative integers to the positive real

Step-1: For the current node, verify whether it contain a left child. If it has, then go to step-2 or else go to step-3 Step-2: Repeat step-1 for left child Step-3: Visit (th

Define tractable and intractable problems Problems that can be solved in polynomial time are known as tractable problems, problems that cannot be solved in polynomial time are

Circular Queues:- A more efficient queue representation is get by regarding the array Q(1:n) as circular. It becomes more convenient to declare the array as Q(O: n-1), when  re

In internal sorting, all of the data to be sorted is obtainable in the high speed main memory of the computer. We will learn the methods of internal sorting which are following:

Any binary search tree must contain following properties to be called as a red-black tree. 1. Each node of a tree should be either red or black. 2. The root node is always bl

State in detail about the Integer Carrier set of the Integer ADT is the set {..., -2, -1, 0, 1, 2, ...}, and  operations on these values are addition, multiplication, subtrac