DATA STRUCTURE - II
Stack and Queues
STACK
A stack is a collection of data items that can be
accessed at only one end, called top.
Items can be inserted and deleted in a stack only
at the top.
The last item inserted in a stack is the first one
to be deleted.
Therefore, a stack is called a Last-In-First-Out
(LIFO) data structure.
2 mains operations on Stack is PUSH & POP
PUSH means inserting new item at top and POP
means deleting item from top.
OTHER STACK TERM
Peek : getting the most recent value of stack i.e
value at TOP
OverFlow : a situation when we are Pushing item
in Stack that is full.
Underflow : a situation when we are Popping
item from empty stack
IMPLEMENTING STACK IN PYTHON
This function will
check Stack is
empty or not
This function will
add new item in
Stack, here setting
top is mandatory
This function is used
to remove item from
stack, also perform
checks before deletion
IMPLEMENTING STACK IN PYTHON
This function will
return the top
most item from the
stack
This function will
display stack items
IMPLEMENTING STACK IN PYTHON
Displaying menu
to user to interact
IMPLEMENTING STACK IN PYTHON