Stack and queue traveral
cannot be traversed
can only peek
Removing data - data structure
when removing data from a structure the data is never deleted
after pointers are updated the memory location is flagged and available
the next time data is added the previous data is overwritten
Stack pop algorithm
check if the stack is empty if so return an error/-1/false and stop (stack underflow)
if the stack is not empty return top item (use a next pointer to find it if necessary)
if top is first available space change top pointer to point where the top pointer was
if top is top item change top pointer to top items next pointer
top is to
if top is top item flag previous top items memory location as available/next
Stack push algorithm
check if the stack is full if it is return an error/-1/false (stack overflow)
if the stack is not full and if top is first empty space then store data in top pointer location with a next pointer indicating its previous item in the queue (null if this is the first item) and update top pointer to next available space
if the stack is not full and if top is top item then find next available location then store data there with a next pointer indicating previous item in the queue (null if this is the first item) and update the top pointer to this location
Queue dequeue algorithm
check if the queue is empty if so return error/-1/false and stop (queue underflow)
if not empty return the data at the top of the front pointer
set front pointer to the nodes next pointer
Queue enqueue algorithm
check if the queue is full if so return error/-1/false and stop (queue overflow)
if queue is not empty store data at location of the end pointer
set next pointer to previous item]set end pointer to next available location
Using arrays
procedural
mutable and static
stored in contiguous data
can use in built indexing as pointers
pointers will be variables which store integers which reference indexes of the arrays
define functions for pop push enqueue dequeue
What do we pass into the functions as parameters and how?
by Ref - memory location during the procedure/function the original value will change
by Val - a new local copy of variable is created changes are made using this val/variable and the original memory location is unchangeable - new variables = more memory required