Professional Documents
Culture Documents
By : Imam M Shofi
What is stack?
stack of satay
stack of CDs
Stacks operations
Push
IsEmpty
empty
IsFull
Initialize
Illustration/example
Operation
Stacks contents
TOP value
1. Initialiaze(S)
<empty>
2. Push(a,S)
3. Push(b,S)
4. Push(c,S)
5. Pop(S)
6. Push(d,S)
7. Push(e,S)
8. Pop(S)
9. Pop(S)
10. Pop(S)
a
ab
abc
ab
abd
abde
abd
ab
a
1
2
3
2
3
4
3
2
1
Exercise
(a)
create stack
push A onto stack
push C*C onto stack
pop item from stack and store in B
push B+A onto stack
pop item from stack and store in A
pop item from stack and store in B
(b)
create stack
push B onto stack
push C onto stack
push A onto stack
A=B*C
push A+C onto stack
pop item from stack and store in A
pop item from stack and store in B
pop item from stack and store in C
Exercise: Converting
Convert these INFIX to PREFIX and POSTFIX :
1.
a)
b)
c)
A/BC/D
(A + B) ^ 3 C * D
A ^ (B + C)
2.
a)
b)
c)
+ /AB C ^ D E
+DE/XY
^+23CD
3.
a)
b)
c)
ABC+
GH+IJ/*
AB^CD+