Stack and queue are dynamic data structures, both support delete operation.
In a stack, delete operation will remove the element which is inserted into lately. It’s called last in, first out, LIFO policy.
Stack just like a pile of files on your desk, you need to take down the file on the top to access the files underneath.
In a queue, delete operation removes the element inserted first. It’s called first-in, first-out, FIFO policy.
Like we stand in a line buy something, it a real-life queue.
The insert operation in the stack is called Push, put data on the top of the stack. And delete operation is called Pop, get the data on the top, and delete it.
This is a simple Java implementation of the stack:
- 20. Valid Parentheses
- 71. Simplify Path
- 155. Min Stack
- 225. Implement Stack using Queues
- 232. Implement Queue using Stacks
- 341. Flatten Nested List Iterator
- 844. Backspace String Compare
The insert operation of the queue is called Enqueue, put data to the end of the queue. The delete operation of the queue is called Dequeue, return the element in the end and delete it.
This is a simple Java implementation of the queue.