Stack ADT, Stack data structure, basic operations performed on stack, stack operation in data structure, push and pop operation in data structure, stack data structure with example
Stack ADT
- Stack is a special kind of list in which all insertions and deletions occur at one end, called the top.
- Stack ADT is a special case of the List ADT. It is also called as a LIFO list or a pushdown list.
- In stack, the element which goes into the stack at last is the one which is coming/extracted out. Hence, it is called LIFO (Last In First Out) list.
Typical Stack ADT
Operations:
- createStack (S) - creates an empty stack.
- top (S) - returns the element at the top of the stack.
- pop (S) - deletes the top element of the stack.
- push (x, S) - Inserts element x at the top of stack S.
- empty (S) - returns true if S is empty and false otherwise
- Stack is a natural data structure to implement subroutine or procedure calls and recursion in many compilers.
Stack
Implementation: Stacks can be implemented using Arrays or Pointers.
Example - Stack operations :
PUSH operation:
Inserts an element into the stack from top only.
POP operation:
Removes an element from the stack through top only.
Inserts an element into the stack from top only.
POP operation:
Removes an element from the stack through top only.
**********