Stack
Practice Questions
Operations in Stack
The two main operations of Stack are
Considered as a linear data structure, or more abstractly a sequential collection, the push and pop operations occur only at one end of the structure, referred to as the top of the stack.
This data structure makes it possible to implement a stack as a singly linked list and a pointer to the top element. A stack may be implemented to have a bounded capacity. If the stack is full and does not contain enough space to accept an entity to be pushed, the stack is then considered to be in an overflow state. The pop operation removes an item from the top of the stack.
In simple words, Stack is nothing but pile of elements which are belongs to similar data type . Stack has a predefined capacity for numbers of elements to be inserted. The element insertion has to done only on Top of the Stack and also removal has to perform from Top of the stack.
Push Operation:
The element always need to insert at Top of the stack. Before inserting an element , we should check Top value is overflowing , which is nothing but Stack capacity increased then it’s predefined capacity .If not, insert the element and increment the Top value by 1.
Pop Operation:
The element always need to delete from the Top of the stack. Before deleting an element , we need to check the stack is underflow, which is nothing but Top value is -1 .If not, delete the element and decrement the Top value by 1.
Try here>>>