-->
Search here and hit enter....

Stack operations in data structure | Part 5

 Hello Viewer! how are you? I hope you are very well. Today I have learned about Stack  Data Structure. below I have written whatever I learn today ...

 

Stack Data structure


STACK

A Stack is a Linear Data Structure in which insertion and deletion of elements are done at only end, which is known as the "Top of Stack".

Stack is called a Last-in,First-out( LIFO ) structure because the last element which is added to the stack is the 1st element which is deleted from the stack.

In the computer's memory stack can be implemented using arrays or linked lists. fig(3) shows the array implementation of stack.


array representation of stack


Every Stack has a variable "top" associated with it.

"top" is used to store the address of the topmost element of the stack.

  • It is the position from where the element will be added or deleted.

There is another variable "MAX", which is used to store the maximum number of elements that the stack can store.

If  "top = NULL", then it indicates that the stack is empty and if "top = MAX-1" then it indicates stack is full.


In fig(3) 👆 , top = 4, so insertion and deletion will be done at this position. Here the Stack can store maximum 6 elements where the indices range from 0-5.

A Stack supports three basic operations: PUSH, POP & PEEP.

The PUSH operation is used to add new element to the "Top Of Stack".

The POP operation is used to remove element from the "Top Of Stack". and

The PEEP operation is used to return the value of "Topmost Stack" without deleting it.


However before inserting new element to the stack we must check for "Overflow" and "Underflow" conditions.

Overflow :- An "Overflow" occurs when we try to insert an element into a stack that is already full.

Similarly "Underflow" occurs when we try to delete an element from the Stack which is already empty.


We will discuss more about Stack operations & implementation after completion of all basic of Data structure.


That's All for Today! I hope You like and understand whatever I have written. If you find any error don't forget to mention it in the comment section or mail me. 💗💗

Note:- I learned this from "Data Structure using C" Book written By Reema Thareja.


FB COMMENTS ()