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
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

Question 1. How can you find out the end of a String? Write an algorithm to find out the substring of a string. 2. Explain the insertion and deletion operation of linked lis

ESO207: Programming Assignment 1 Due on 6 Sept, 2015. To be submitted online. Problem In this assignment you are required to implement k-way Merge Sort algorithm. In this version p

how do we use 4-discs stack to solve tower of hanoi problem and write an algorithm to solve it?


Q. Write down the binary search algorithm and trace to search element 91 in following given list: 13          30          62           73         81         88             91

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 mission (sho

Explain about Hidden-surface Hidden-line removal refers to wire-frame diagrams without surface rendering and polygonal surfaces with straight edges. Hidden-surface removal ref

The data structure needed to evaluate a postfix expression is  Stack

Q. Using the following given inorder and preorder traversal reconstruct a binary tree Inorder sequence is D, G, B, H, E, A, F, I, C