Many everyday piles work in one way only: you put things on top and take things from the top. A stack is the data structure that follows this rule. This page defines it as an abstract data type, independent of how it is stored.
Last in, first out
Operations
Operation
What it does
If not possible
create(S)
Make S an empty stack
—
push(S, x)
Put x on the top of S
Overflow (no room)
pop(S)
Remove and return the top item
Underflow (stack empty)
peek(S) (or top)
Return the top item without removing it
Underflow
is_empty(S)
True if S has no items
—
is_full(S)
True if no more items fit (array implementation)
—
Trying to push onto a full stack is overflow; trying to pop from an empty stack is underflow. In every good implementation, push, pop and peek take O(1) time, because they touch only the top.
Where the name “push” comes from
Canteens often keep trays in a spring-loaded rack. Putting a tray on top pushes the pile down against the spring; taking one off lets the pile pop up a little. Only the top tray is ever reachable.
Key takeaways
A stack is a list with insertion and deletion at one end, the top: LIFO.
Operations: push, pop, peek, is_empty (and is_full for arrays); all O(1).
Overflow = push onto a full stack; underflow = pop from an empty stack.
Items come out in reverse order of insertion.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Define a stack and explain the push and pop operations with an example showing the position of top.
Show worked answer
A stack is an ordered list in which all insertions and deletions are made at one end, the top, so the last item inserted is the first removed (LIFO). Push(x) places x on the top; if the stack is full, overflow occurs. Pop removes and returns the top item; if the stack is empty, underflow occurs. Example (bottom → top, top marked): empty; push 10 → [10] top = 10; push 20 → [10 20] top = 20; push 30 → [10 20 30] top = 30; pop returns 30 → [10 20] top = 20.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-208/stacks/the-stack-adt/ to read this page.