Postfix expression algorithm, Data Structure & Algorithms

Write an algorithm to calculate a postfix expression.  Execute your algorithm using the given postfix expression as your input : a b + c d +*f ↑ .

To evaluate a postfix expression by using the given values:

clear the stack

symb  = next input character while(not end of input)

{

if (symb is an operand)

push onto the stack;

else

{

pop two operands from the stack;

result=op1 symb op2;

push result onto the stack;

}

symb = next input character;

}

return (pop (stack));

The input postfix expression is given as:- ab+cd+*f^

Symb                 Stack                                          Evaluation a    a

b                    a b

+                   pop a and b                                 (a + b) Push (a + b)

c                    (a + b) c

d                   (a + b) c d

+                   pop c and d                                 (c + d) Push (c + d)

*                    pop (a + b) and (c + d)                (a + b) * (c + d)

f                    (a + b) * (c + d) f

^                    pop (a + b) * (c + d) and f           (a + b) * (c + d) ^ f

The result of evaluation is ((a + b) * (c + d)) ^ f

Posted Date: 7/9/2012 10:03:51 PM | Location : United States







Related Discussions:- Postfix expression algorithm, Assignment Help, Ask Question on Postfix expression algorithm, Get Answer, Expert's Help, Postfix expression algorithm Discussions

Write discussion on Postfix expression algorithm
Your posts are moderated
Related Questions
Complexity classes All decision problems fall in sets of comparable complexity, called as complexity classes. The complexity class P is the set of decision problems which ca

since the gregorian calendar was introduced in 1752,a leap year occurs every 4 years.you are to write a pseudo code to find out whether a year is a leap year.your progrm should dis

Z-Buffer Algorithm Also known as the Depth-Buffer algorithm, this image-space method simply selects for  display the polygon or portion of a polygon that is nearest to the view

Symbols of ADT oeprations All Symbol ADT operations are implemented in Symbol class, except toSymbol(), which is implemented in classes (like String) which can generate a Symb


ST AC K is explained as follows : A stack is one of the most usually used data structure. A stack is also called a Last-In-First-Out (LIFO) system, is a linear list in

Q. Give the adjacency matrix for the graph drawn below:                                                 Ans: Adjacency matrix for the graph given to us

1) Which graph traversal uses a queue to hold vertices which are to be processed next ? 2) Which of the graph traversal is recursive by nature? 3) For a dense graph, Prim's a

Explain about the Structured types - Built-In Types Values of the carrier set are not atomic, consisting rather than several atomic values arranged in some way. Common illu

By changing the NULL lines in a binary tree to the special links called threads, it is possible to execute traversal, insertion and deletion without using either a stack or recursi