This Repo required for Asac labs class 2
A stack is a data structure that consists of Nodes. Each Node references the next Node in the stack, but does not reference its previous.
FILO (First In Last Out)
This means that the first item added in the stack will be the last item popped out of the stack.
LIFO (Last In First Out)
This means that the last item added to the stack will be the first item popped out of the stack.
Push :
ALOGORITHM push(value)
// INPUT <-- value to add, wrapped in Node internally
// OUTPUT <-- none
node = new Node(value)
node.next <-- Top
top <-- Node
Pop :
ALGORITHM pop()
// INPUT <-- No input
// OUTPUT <-- value of top Node in stack
// EXCEPTION if stack is empty
Node temp <-- top
top <-- top.next
temp.next <-- null
return temp.value
Peek :
ALGORITHM peek()
// INPUT <-- none
// OUTPUT <-- value of top Node in stack
// EXCEPTION if stack is empty
return top.value
IsEmpty :
ALGORITHM isEmpty()
// INPUT <-- none
// OUTPUT <-- boolean
return top = NULL
A Queue is a linear structure which follows a particular order in which the operations are performed.
Rear - This is the rear/last Node of the queue.
FIFO (First In First Out)
This means that the first item in the queue will be the first item out of the queue.
LILO (Last In Last Out)
This means that the last item in the queue will be the last item out of the queue.
Enqueue :
ALGORITHM enqueue(value)
// INPUT <-- value to add to queue (will be wrapped in Node internally)
// OUTPUT <-- none
node = new Node(value)
rear.next <-- node
rear <-- node
Dequeue :
ALGORITHM dequeue()
// INPUT <-- none
// OUTPUT <-- value of the removed Node
// EXCEPTION if queue is empty
Node temp <-- front
front <-- front.next
temp.next <-- null
return temp.value
Peek :
ALGORITHM peek()
// INPUT <-- none
// OUTPUT <-- value of top Node in stack
// EXCEPTION if stack is empty
return front.value
IsEmpty :
ALGORITHM isEmpty()
// INPUT <-- none
// OUTPUT <-- boolean
return front = NULL