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
what is hashing? what are diffrent method of hashing?

Readjusting for tree modification calls for rotations in the binary search tree. Single rotations are possible in the left or right direction for moving a node to the root position

Write a function that performs integer division. The function should take the large number in memory location 1 and divide it by the large number in memory location 2 disregarding

What do you understand by term structured programming? Explain the structured programming as well.                                 Ans. S tructured Programming is expla

discuss the operating system under the following: MONOLITHIC SYSTEM,LAYER SYSTEM AND VIRTUAL MACHINES

Beauty Salon is a system to be designed to manage the booking and the payment of a single beauty parlour. Beauty Therapists: A beauty parlour has a number of staff members mo

Post order traversal: The children of node are visited before the node itself; the root is visited last. Each node is visited after its descendents are visited. Algorithm fo

What are expression trees?  The leaves of an expression tree are operands, like as constants or variable names, and the other nodes have operators. This certain tree happens to

Efficiency of Linear Search How much number of comparisons is there in this search in searching for a particular element? The number of comparisons based upon where the reco

Data records are stored in some particular sequence e.g., order of arrival value of key field etc. Records of sequential file cannot be randomly accessed i.e., to access the n th