ALOGORITHM push(value)
// INPUT <-- value to add, wrapped in Node internally
// OUTPUT <-- none
node = new Node(value)
node.next <-- Top
top <-- Node
ALGORITHM peek()
// INPUT <-- none
// OUTPUT <-- value of top Node in stack
// EXCEPTION if stack is empty
return top.value
return top = NULL
#### Queue
- Terminology for a queue is
1. Enqueue - Nodes or items that are added to the queue.
2. Dequeue - Nodes or items that are removed from the queue. If called when the queue is empty an exception will be raised.
3. Front - This is the front/first Node of the queue.
4. Rear - This is the rear/last Node of the queue.
5. Peek - When you peek you will view the value of the front Node in the queue. If called when the queue is empty an exception will be raised.
6. IsEmpty - returns true when queue is empty otherwise returns false.
- Queues follow these concepts:
1. FIFO: First in First Out
2. LILO: Last in Last Out
- pseudocode for the enqueue method:
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
- pseudocode for the dequeue method:
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
- pseudocode for a peek:
ALGORITHM peek() // INPUT <– none // OUTPUT <– value of the front Node in Queue // EXCEPTION if Queue is empty
return front.value ``