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;



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
Define Big Omega notation Big Omega notation (?) : The lower bound for the function 'f' is given by the big omega notation (?). Considering 'g' to be a function from the non-n

Task If quicksort is so quick, why bother with anything else? If bubble sort is so bad, why even mention it? For that matter, why are there so many sorting algorithms? Your

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

A shop sells books, magazines and maps. Every item is identified by a unique 4 - digit code. All books have a code which starts with 1, all maps have a code starting with 2 and all

In-order Traversal  This process when executed iteratively also needs a stack and a Boolean to prevent the implementation from traversing any portion of a tree twice. The gener

circular queue using c

According to this, key value is divided by any fitting number, generally a prime number, and the division of remainder is utilized as the address for the record. The choice of s

How sparse matrix stored in the memory of a computer?

Comparison Techniques There are several techniques for determining the relevancy and relative position of two polygons. Not all tests may be used with all hidden-surface algori

Explain about the Abstract data type Abstract data type (ADT) A set of values (the carrier set) and operations on those values