Stacks and Queues
Notes
Stack:
- Push: add a node to the top of the stack
- Pop: remove a node from the top of the stack
- Top: the top node on a stack
- Peek: view the value of the top of the stack
- isEmpty: checks if a stack is empty or not
- FILO: first in, last out
- LIFO: last in, first out
Queue:
- Enqueue: add a node to the rear of the queue
- Dequeue: remove a node from the front of the queue
- Front: the first node in the queue
- Rear: the last node of the queue
- Peek: view the value at the front of the queue
- isEmpty: checks if the queue is empty
- FIFO: first in, first out
- LILO: last in, last out
Lesson
Stack Analogy
To help me understand a stack I think of playing a game with a deck of cards. The deck of represents the stack and you can only draw a card (pop) or add a new card (push) on top of the deck. You can also look at the top card of the deck (peek).
Queue Analogy
A real world concept thats help me understand what a queue is in when programming is almost exactly the some a thing, a queue, or a line rather. Specifically, a line of people but the only thing each person (node) knows is who is next in line.
Things I want to know more about
- Similarities and differences between linked lists, stacks, and queues
References