Tutorial Activity Stack
Tutorial Activity Stack
Learning Outcomes
This Tutorial encompasses activities 3A and 3B.
Activity 3A
Activity Outcome: Use array and linked list to represent stack of data structure
The stack data structure can be implemented in two ways, which are:
i. Using arrays
ii. Using linked list
the top
[2] 45
[1] 68
[0] 99
Figure 1
2. Convert the stack data structure at Figure 1 to linked list. Then, show top of stack
45 68 99
head
3. Differentiate implementation of stack using linked list and array
Size Size of the array is fixed Size of linked list is not fixed
Test full Memory allocation is done at Memory allocation is done at run time
stack compile time
Activity 3B
Activity Outcome: Array implementation operation of stack
Draw a suitable stack diagram for each statement below. Given that the Stack of T contents of
four (4) elements.
Procedure:
T T T T
pop ()
[2] [2]
pop ()
[1] [1] 600
[0] 700 [0] 700
T T
2. Imagine we have one empty stack of integers, s1. Draw a picture of each stack after the
following operations being performed:
push (9)
pop ()
[5] [5]
[4] [4] 11
15
[3] 9 push (15) [3] 99
[2] 7 [2] 7
[1] 5 7
[1] 5
5
[0] 3 [0] 3
s1 s1
3. Imagine we have two empty stacks of integers, t1 and t2. Draw a picture of each stack
after the following operations being performed:
end loop
[5] [5] [5] [5] [5] [5]
[4] [4] [4] [4] [4] [4]
push (2), t1 push (6), t1
[3] [3] [3] [3] [3] [3]
[2] [2] [2] [2] [2] [2]
[1] [1] [1] [1] [1] 6 [1]
[0] [0] [0] 2 [0] [0] 2 [0]
t1 t2 t1 t2 t1 t2
push (8), t1
stack is full
push (12), t1
t1 t2 t2 t1 t2
push (15), t2
[5] [5] [5] [5] [5] [5]
[4] [4] [4] [4] [4] [4]
push (1), t2 push (5), t2
[3] [3] [3] [3] [3] [3]
[2] [2] 1 [2] [2] [2] [2]
[1] [1] 5 [1] [1] 5 [1] [1]
[0] [0] 15 [0] [0] 15 [0] [0] 15
t1 t2 t1 t2 t1 t2
pop (), t2
[5] [5]
[4] [4]
[3] [3]
[2] [2]
[1] [1] 5
[0] [0] 15
t1 t2