0% found this document useful (0 votes)
101 views5 pages

EXERCISE 3 (Done)

This document describes operations on stacks using arrays and linked lists. It provides examples of implementing stacks in real-world situations and defines common stack operations like push, pop, isEmpty and isFull. Diagrams are included to demonstrate stacks at different points in operations like insertion, deletion and transferring elements between stacks.

Uploaded by

BOBBY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views5 pages

EXERCISE 3 (Done)

This document describes operations on stacks using arrays and linked lists. It provides examples of implementing stacks in real-world situations and defines common stack operations like push, pop, isEmpty and isFull. Diagrams are included to demonstrate stacks at different points in operations like insertion, deletion and transferring elements between stacks.

Uploaded by

BOBBY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Exercise 3: STACKS

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.
2. List and describe 5 operations in a stack:

Operations name Description

i. createStack() Initialize top

ii. push(char)
Insert item onto stack
iii. pop() Delete item

iv. isEmpty() Check whether a stack is empty

v. isFull() Get item at top

3. Show the top of given stack using arrays

[2] 45
[1] 68
[0] 99
Figure 1

4. Convert the stack data structure at Figure 1 to linked list. Then, show top of stack
5. Differentiate implementation of stack using linked list and array

Array Linked List

Top of
stack

Size

Element
Insertion

Test full
stack

6. Draw a suitable stack diagram for each statement below. Given that the Stack of T
contents of four (4) elements.

Procedure:

Step 1: Create new stack (T)


Step 2: Check stack : full or empty
Step 3: If empty;

a) Insert item to the stack as below:


i. Push (700, &T)
ii. Push (600, &T)
iii. Push (500, &T )

b) Delete item from the stack as below:


i. Pop (500, &T)
ii. Pop (600, &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:

Step 1: Create new stack (s1)


Step 2: pushStack (s1, 3)
Step 3: pushStack (s1, 5)
Step 4: pushStack (s1, 7)
Step 5: pushStack (s1, 9)
Step 6: pushStack (s1, 11)
Step 7: pushStack (s1, 13)
Step 8: loop no emptyStack (s1)
i. popStack
ii. popStack
iii. pushStack (s1, 15)
Step 9: end loop
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) i.
popStack (t1, x)
popStack (t1, x)
pushStack (t2, 15)
pushStack (t2, 5)
pushStack (t2, 1)
popStack (t2, x)

You might also like