Monday, September 12, 2016
Stack algorithms of pop operation
Stack algorithms:
This algorithm is for deletion of an element from stack
also it is also known as pop element from stack:
This algorithm is for deletion of an element from stack:
1)
if(
top == NULL)
a)
print“Stack
is empty”
b)
return
2)
temp = top
3)
num = temp→data
4)
top = top→link
5)
delete temp
6) return num
7) Exit
|
This
algorithm is for evaluation of postfix expression:
Description: Here P is
a postfix expression and this algorithm evaluates it.
1.
Add a “)” right parenthesis at the
end of P.
2.
Scan P from left to right and repeat
steps 3 & 4 for each element
Of P until “)” is encountered.
3.
If
an operand is encountered, push it onto stack.
4.
If an
operator U is encountered then:
(a) Pop the top two elements from stack, where A is the
Top element and B is the next to top element.
(b) Evaluate B U A.
(c) Place the result of (b) back on stack.
[End of Step 4 If]
[End of step 2 For Loop]
5.
Set
VALUE equal to the top element on the stack.
6.
Exit.
|
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment