A Stack and a Queue are both linear data structures that store a sequence of elements — but they differ in one critical way: the order in which elements leave.
A Stack is LIFO (Last In, First Out) — the most recently added element is always removed first, like a stack of plates. A Queue is FIFO (First In, First Out) — the oldest element is always removed first, like people waiting in line.
push() adds to the top. pop() removes from the top. The last item pushed is always the first item popped.
enqueue() adds to the back. dequeue() removes from the front. The first item enqueued is the first item dequeued.
Push, pop, enqueue, and dequeue are all O(1) operations — constant time regardless of size.
TIPStacks are used whenever you need to reverse something or track nested structure — think recursion, undo, and bracket matching. Queues are used whenever order of arrival matters — think BFS, task scheduling, and print spoolers.