Stacks & Queues
What is a Stack?
Data structure that consists of Nodes. Each Node references the next Node in the stack.
>>
Common terminology for a stack is:
- Push => put items into the stack
- Pop => remove items from the stack.
- Top => This is the top of the stack.
- Peek => view the value of the top Node in the stack.
- IsEmpty => returns true when stack is empty otherwise returns false.
Stacks follow :
(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.
What is a Queue?
Data structure that consists of Nodes. Each Node references the next Node in the queue.
>>
Common terminology for a queue is:
- Enqueue => add item the queue.
- Dequeue => remove items the queue.
- Front => the first Node of the queue.
- Rear => the last Node of the queue.
- Peek =>view the value of the front Node in the queue.
- IsEmpty => returns true when queue is empty otherwise returns false.
Queues follow:
(FIFO) First In First Out
This means that the first item in the queue will be the first item out of the queue.