Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
LECTURE NOTES OF ADVANCED DATA STRUCTURE (MT-CSE 110)<br />
be written "3 4 5 * −", which unambiguously means "3 (4 5 *) −" which of course<br />
reduces to "3 20 ‐".<br />
Interpreters of Reverse Polish notation are often stack‐based; that is, operands<br />
are pushed onto a stack, and when an operation is performed, its operands are<br />
popped from a stack and its result pushed back on. Stacks, and therefore RPN,<br />
have the advantage of being easy to implement and very fast.<br />
Algorithm :<br />
This algoritm finds the value of an arithmetic expression P written in postfix<br />
notation.<br />
<strong>1.</strong>Add a right parenthesis”)” at the end of P.<br />
[This act as sentinel.]<br />
2.Scan P from left to right and repeat step<br />
3and 4for each element of P until the sentinel”)” is encountered.<br />
3.If an operand is encountered then:<br />
a)Remove the two TOP elements of STACK where A is the top element and B is<br />
the next‐to‐top element.<br />
b)Evaluate B*A.<br />
c)Place the result of(b) back on STACK<br />
[End of if structure.]<br />
[End os step 2 loop.]<br />
5.SET VALUE equal to the element on SATCK<br />
6.EXIT<br />
Prepared By :<br />
Er. Harvinder Singh<br />
Assist Prof., CSE, H.C.T.M (Kaithal) Page ‐ 172 ‐