Stack with Their Operation :


  • A stack is an Abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example – a deck of cards or a pile of plates, etc.
  • Stack is an ordered list of the same type of elements.
  • It is a linear list where all insertions and deletions are permitted only at one end of the list .
  • Stack is a LIFO(Last In First Out) structure.
  • In a stack, when an element is added it goes to the top of the stack.

stack


Definition 
 :- "Stack is a collection of similar data items in which both insertion and deletion operations are performed based on LIFO principle."

There are four basic operation performed in a Stack : 

  1. push() : This function is used to add or insert new element into the stack.
  2. pop()  : This function is used to delete or remove an element from the stack.
  3. peep() : This function is used to find the index value from stack.
  4. change() : This function is used to change the index value from stack.

When a stack is completely full it is said to Overflow state and if stack is completely empty, it is said to be Underflow state.

Stack allows operations at one end only

Stack behaves like a real life stack. For example, in a real life we can remove a plate or dish from the top of the stack only or while playing a deck of cards, we can place or remove a card from top of the stack only.

Similarly, here also we can only access the top element of a stack.
 
According to its LIFO structure the element which is inserted last is accessed first.


Implementation of element in Stack

Stack Push Operation
fig.1 : push() operation

The above diagram represents a stack insertion operation.

In a stack, inserting and deleting of elements are performed at a single position which is known as TOP.

Insertion operation can be performed using push() function.

New element is added at TOP of the stack and removed from top of the stack, as shown in the diagram below.


Deletion of element in Stack

Stack Pop Operation
fig. 2 : pop() operation

An element is removed from top of the stack .

Delete operation is based o LIFO principle. This operation is performed using a pop() function.

It means that the insertion and deletion operation are performed at one end at TOP.
 

How was your experience on reading my post. Don't forget to comment. Share your reviews to us.