Stacks
Stacks
Martinez
Stacks
y A stack is a list in which insertion and deletion take place at
the same end
y This end is called top
y The other end is called bottom
Empty
maxlength
Static Implementation
1
3
2
2
1
A better Implementation:
Anchor the bottom of the stack at the
bottom of the array
Let the stack grow towards the top of the
array
Top indicates the current position of the
first stack element.
10
Static Implementation
A better Implementation:
top
1 First Element
Second Element
2 .
.
maxlength Last Element
11
Dynamic Implementation of Stacks
y As we know that dynamic stack is implemented using
linked‐list.
y In dynamic implementation stack can expand or shrink
with each PUSH or POP operation.
y PUSH and POP operate only on the first/top cell on the list.
Top
x y z NULL
Stack applications
y “Back” button of Web Browser
y History of visited web pages is pushed onto the stack
and popped when “back” button is clicked