Stacks Programming activity
Activity 1: Complete the sentence:
The pointer always points to . When the stack is empty the
pointer value is ______________-1____
Activity 2: Create a stack and stack procedures on it listed below.
First you need to create your stack data structure by....
i
-1
0
1
2
3
4
Data
-----None
None
None
None
None
Ponter
<
Creating a blank array of length 5. Hint: Use “” or None.
Creating a push function that takes a character, the array and the pointer as arguments and will
return the new stack with pointer value.
Creating a pop function that takes the array and pointer as arguments and returns the new stack,
pointer and popped value.
Activity 3: Stack procedures – Implement the following procedures on your stack
Push(A)
Push(B)
Push(C)
Pop()
Push(D)
i
-1
0
1
2
3
4
Push(E)
Pop()
Push(F)
Push(G)
Push(H)
Data
-----A
B
Pinter
…now show what your stack would look like using the table.
Extension: What happens when you push H? What 2 additional functions should you create? Create these
functions.
_______________________________________________________________________________________
_______
Super extension: What type of variable would make your code more simple by reducing the number of
arguments sent to the functions? Adapt your code to use this technique.
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
_______________
Queues Programming activity
Activity 1: Complete the sentence:
A queue has ____ pointers called _________ and
_________.
i
-1
0
1
2
3
4
Data
-----None
None
None
None
None
front
<
back
<
The _______ pointer always points to item the at the
_______ of the queue. The _______ pointer always
points to _________ the at the back of the queue. When the queue is empty the
pointer values are __________________.
Activity 2: Create a queue and run the stack procedures on it listed below.
First you need to create your queue data structure by....
Creating a blank array of length 5. Hint: Use “” or None.
Creating an enqueue function that takes a character, the array and the two pointers as arguments
and will return the queue stack with pointer value.
Creating a dequeue function that takes the array and pointers as arguments and returns the new
queue, pointers and dequeued value.
Activity 3: Queue procedures – Implement the following procedures on your queue
Enqueue(A)
Enqueue(B)
Dequeue()
Enqueue(C)
Dequeue()
Enqueue(D)
i
-1
0
1
2
3
4
Data
------
front
back
Enqueue(E)
Enqueue(F) …now show what your queue would look like using the table.
Extension: What happens when you enqueue F? What 2 additional functions should you create? Create
these functions.
_______________________________________________________________________________________
_______
What would happen if you followed the queue procedures with 3 Dequeues?
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
____________________