HomeData Structures

What is Push function in Simple Stack ?

What is Push function in Simple Stack ?

Simple Stack :Stack is an ordered list of similar data type. Stack is a LIFO structure. (Last in First out). push() function is used to insert new elements into the Stack and pop() is used to delete an element from the stack. Both insertion and deletion are allowed at only one end of Stack called Top.

Simple Stack

Push Refers as “Adding Elements onto Stack“.
Push Operation carried out in following

2 steps –

First Increment Variable “top“ so that it now refers to next memory location.
Secondly Add Element Onto Stack by accessing array.

void Push()
{ if(i>=5)
cout<<"Array is Full";
for(int j=i;j>=0;j--)
{ num[j+1]=num[j]; }
cout<<"Enter Value: ";
cin>>num[0]; i++;

Pop function in simple Stack

void Pop(){
cout<<"Error!There is no Value"<<endl;
{for(int j=0;j<i;j++)

Display function in simple Stack

void show(){
cout<<"Array is Empty"<<endl;
for(int j=0;j<i;j++)
{ cout<<num[j]<<endl;

Comments (0)

Leave a Reply