Unit content
Stacks and queues
Some data structures deliberately restrict which element can be removed next.
A stack uses last-in, first-out order. A queue uses first-in, first-out order.
Stacks
A stack exposes operations such as
push(value)
pop()
top()
The most recently pushed value is the first one removed. Function-call stacks, undo histories and depth-first searches naturally use this ordering.
Queues
A queue exposes operations such as
enqueue(value)
dequeue()
front()
The earliest enqueued value is removed first. Work queues, buffering and breadth-first searches use this ordering.
Interface versus implementation
A stack or queue describes an access discipline, not one unique memory representation. Both can be implemented with arrays or linked structures.
The implementation determines practical costs such as allocation overhead, locality and resizing, while the abstract interface determines which operations callers are allowed to perform.