Lec 4 - 5 - Stack and Queue 2
Lec 4 - 5 - Stack and Queue 2
Stack
• A stack is an ordered list in which insertion and deletion are done
at one end, called top.
• The last element inserted is the first one to be deleted. Hence, it is
called the Last In, First Out (LIFO) or First In, Last Out (FILO) list.
• You can visualize a stack as a collection of items that are stacked
on top of one another, like a pile of plates in a cafeteria or a stack
of books.
• When you add a new plate, it goes on the top, and when you take
one off, you take the one from the top as well.
Stack
• Special names are given to the two changes that can be made to a
stack.
• When an element is inserted in a stack, the operation is called
push, and when an element is removed from the stack, the
operation is called pop.
Stack