PROGRAM TO PERFORM PUSH OPERATION ON STACK USING ARRAY

/*PROGRAM TO PERFORM PUSH OPERATION ON STACK USING ARRAY*/
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#define MAX 5
void main()
{
int maxstk,top=-1,n,a[MAX],i;
char ch;
clrscr();
//PUSH OPERATION
cout<<“Pushing elements into the stack: “<<endl;
do
{
if(top>=MAX-1)
{
cout<<“Stack is overflow”<<endl;
break;
}
else
{
top++;
cout<<“Enter element to be pushed: “;
cin>>n;
a[top]=n;
}
cout<<“Do you want to push more elements?? “;
cin>>ch;
}while(ch==’y’);
cout<<“After push operation elements of the stack are:”<<endl;
for(i=0;i<=top;i++)
{
cout<<a[i]<<“\t”;
}
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *