IMPLEMENTATION OF STACK USING ARRAYS IN C++

#include<iostream.h>
#include<conio.h>
int i, top, item, s[10];
int max = 10;
void push ( int item, int s[ ] )
void pop (int s[ ] )
void display ( int s[ ] )
void display (int s[ ] )

void main( )
{
int ch;
clrscr( );
top = -1;
do
{
cout<< “\n\n 1.PUSH \n 2.POP \n 3. EXIT \n” ;
cout<<“ \n ENTER UR CHOICE: “;
cin>>ch;
switch (ch)
{
case 1:
cout<< “\t\tPUSH\n”;
if (top >= max – 1)
{
cout<<“\n STACK IS FULL \n “;
}
else
{
cout<<“\n ENTER AN ELEMENT :”;
cin>>item;
push (item, s);
}
display(s);
break;
case 2:
cout<<"\t\nPOP\n";
if (top < 0 )
{
cout<<"\nSTACK IS EMPTY";
}
else
{
pop(s);
}
display(s);
break;
case 3:
cout<<"GOOD BYE!!!!";
break;
} }
while (ch!= 3)
getch( );
}
void push ( int item, int s[ ] )
{
top = top + 1;
s[top] = item;
}
void pop(int s[ ] )
{
item = s[top];
top = top – 1;
cout<<"\n DELETED ELEMENT IS\n"<<item);
}
void display( int s[ ] )
{
cout<<"\n";
for ( i = top; i >= 0; i-- )
{
cout<<"\n"<<s[i];
}
}

No comments:

Post a Comment