Stack
Stack is the concept of "what you put in last get put out first". This concept can be put metaphorically as a stack of dishes or a tennis ball cylinder. It's not possible to take something out if there is something else above it in the stack.
visualization:
Operations:
- push (insertion) : adding something on top of the stack.
- pop (deletion) : taking something from the top of the stack.
Queue
The concept is actually really similar to the concept of stack. The name "queue" can be taken quite literally since that is basically what it is, a queue. In a queue, the first person that gets in a queue, gets out on the end of the queue first. This is the concept of "What you put in first, get put out first".
visualization:
It should be pretty obvious by now that the difference between queue and stack is their input and output direction. The rear is the input direction of the queue and holds the last data in the queue. The head, on the other hand, holds the first data that was inputted and is the output direction of the queue.
Operations:
- Enqueue (insertion) : add a new data to the queue. This happens on the rear of the queue.
- Dequeue (deletion) : take out the first data that was inputted in. This happens on the front of the queue.


No comments:
Post a Comment