C Programming language

adplus-dvertising
C - Stack in Data Structure
Previous Home Next

A Stack is non-primitive data structure. It is an ordered list in which the addition of new element or deletion of the existing element is done only from one end which called as TOP of Stack. As all the insertion and deletion is performed from only one end, the last added element will be deleted first, so the stack is also known as Last In First Out (LIFO) data structure. The most frequently accessed element in the stack is the top most element, whereas least accessed element is the bottom of the stack.

Whenever a stack is created, the stack base or the bottom remains fixed while whenever a new element is added only the top is increased and goes on increasing whenever a new element is added to the stack and decreases whenever a particular element is deleted.

Implementation of Stacks in Data structures
  1. Static Implementation: Static Implementation uses arrays to create a stack. Static implementation is a very simple technique but it is not a flexible way of creation, as the size of the stack has to be declared in advance and after which its size can't be modified

  2. Dynamic Implementation: Dynamic Implementation is also called the linked list representation and use pointers to implement stack type of data structure.

Operation on the Stacks

The basic operations that can be performed on the  stack are as follows :

  1. PUSH : The process of addition of new element to the stack is called the PUSH operation. As we know already whenever an element is added it will add to the top of the stack and the value of top will be incremented by one.

  2. POP : The process of deleting an existing element from the top of the stack is called the POP operation. Whenever an element is popped up from the top of stack the value of top is decremented by one.

Previous Home Next