Professional Documents
Culture Documents
1. A stack is a data structure that works on the principle of Last in First out (LIFO). List and
draw 3 examples implementation of stack in real life situation.
Stack of
Cookies
Tennis Ball
Stack of Paper
2. List and describe 5 operations in a stack:
i. PUSH
ii. POP
iii. PEEK
iv. IsFull
v.IsEmpty
[2] 45
[1] 68
[0] 99
Figure 1
Answer = 45 [2]
4. Convert the stack data structure at Figure 1 to linked list. Then, show top of stack
2 45 1 68 0 99
Head node 2 1 0
Test full
stack IsEmpty IsFull
6. Draw a suitable stack diagram for each statement below. Given that the Stack of T
contents of four (4) elements.
Procedure:
500
Stack T
500
Pop 500 Pop 600
600 600
Stack T
Step 4: Draw the final picture after all of the operations has been performed.
7. Imagine we have one empty stack of integers, s1. Draw a picture of each stack after the
following operations being performed:
7 7
Push
Push Push 5 Push 5 9 5
3 5 7
3 3 3
3
13
15 11 11 11 Push
Push
15 Pop pop13 Push 11
9 9 9 9 9
11 13
7 7 7 7 7
5 5 5 5 5
3 3 3 3 3
Stack s1
8. Imagine we have two empty stacks of integers, t1 and t2. Draw a picture of each stack
after the following operations being performed:
pushStack (t1, 2)
pushStack (t1, 6)
pushStack (t1, 8)
pushStack (t1, 9)
pushStack (t1, 10)
pushStack (t1, 12)
popStack (t1, x)
popStack (t1, x)
pushStack (t2, 15)
pushStack (t2, 5)
pushStack (t2, 1)
popStack (t2, x)
2 2 2 2
12
10 10 10
9 9 Pop 9 9
Pop Push Push
10 12
8 8 8 12 8 10
6 6 6 6
2 2 2 2
Stack t1
1
Push Push Push Pop 1
5 5 5 5
15 1
15 15 15 15
Stack t2