Stacks and queues are linear data structures that differ in how elements are added and removed.
Stack (LIFO)
Last In, First Out: the most recently added element is the first to be removed. Imagine a stack of plates — you can only add or take from the top.
Typical operations:
push— add an element to the top.pop— remove the top element.peek/top— inspect the top element without removing it.
Queue (FIFO)
First In, First Out: the first element added is the first to be removed. Like a real-world line, items join at the back and leave from the front.
Typical operations:
enqueue— add an element to the back.dequeue— remove the element at the front.peek/front— inspect the front element without removing it.