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 a linear array? An array is a way to reference a series of memory locations using the similar name. Every memory location is shown by an array element. An  array elemen

reverse the order of elements on a stack S using two additional stacks using one additional stack

Colouring The use of colours in CAD/CAM has two main objectives : facilitate creating geometry and display images. Colours can be used in geometric construction. In this case,

First - Fit Method: -    The free list is traversed sequentially to search the 1st free block whose size is larger than or equal to the amount requested. Once the block is found it

This is the most extensively used internal sorting algorithm. In its fundamental form, it was invented by C.A.R. Hoare in the year of 1960. Its popularity lies in the easiness of i

Q.1 Write procedures/ Algorithm to insert and delete an element in to array. Q.2. Write an algorithm for binary search. What are the conditions under which sequential search of


A B-tree of minimum degree t can maximum pointers in a node T pointers in a node.

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

advanatges of dynamic data structure in programming