Stack
1. Stack is a non-primitive linear data structure.
Primitive (predefined)
Non-primitive (User-defined)
2. It is an ordered list in which the addition
of new data items and deletion of the already existing data items is done from only one
end known as “Top Of Stack (TOS)”
When the stack is empty then the Top Of the Stack is -1 (TOS = -1).
3. The last added element will be the
first to be removed from the stack. This is the reason stack is called “Last In
First Out (LIFO)” type of list.
Real-Life Example:
When we put a bunch of books one on top
of the other. So, if we want to pick up a book from a bunch of books then we
pick up the book above. And how it works in the stack.
Operations on the stack:
There are two operations of the stack.
1. PUSH Operation: The process of adding
a new element to the top of the stack is called PUSH Operation.
2. Every new element is adding to the stack
top is incremented by one.
TOS = TOS+1;
3. In case the stack is full and no new element
can be added it is called stack full or stack overflow condition.
2. POP Operation: The process of top of the stack is called POP Operation.
1. After every pop operation, the stack
is decremented by one.
TOS = TOS – 1;
2. If there is no element on the stack
and the pop is performed then this will result in the stack underflow condition.
0 Comments