You can build a stack on an array or on a linked list. Both keep push and pop at O(1). The choice mostly changes memory behavior, not the contract callers see.
With an array, you track the top index. Push writes at that index and bumps it. Pop reads and steps back. The array grows when full, occasionally copying everything to a bigger block.
With a linked list, the head node is the top. Push adds a new head; pop unlinks it. No copying ever happens, but each node costs an extra pointer.
stack.push(4); // top is now 4
stack.pop(); // returns 4, top restored
Most languages hand you a ready stack through their dynamic array type. Reach for that first.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓