#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
int top=-1;
int *stk;
void PUSH(int n)
{ if(top>n)
cout<<"\nSTACK OVERFLOW";
else
{ top++;
cout<<"\nEnter the element to be inserted:";
cin>>stk[top];
}
}
void POP()
{ if(top<0)
cout<<"\nSTACK UNDERFLOW";
else
{ int item=stk[top];
top--;
cout<<"\nThe deleted element is:"<<item;
}
}
void PEEP()
{ int pos;
cout<<"\nEnter the element position u want to search:";
cin>>pos;
if(top-pos+1<=0)
cout<<"\nSTACK UNDERFLOW";
else
{ cout<<"\nRequired element:"<<stk[top-pos+1];
}
}
void TRAVERSE()
{ int pos,value;
/* cout<<"\nEnter the position u want to change value:";
cin>>pos;
cout<<"\nEnter the value to be change:";
cin>>value;
if(top-pos+1<=0)
cout<<"\nSTACK UNDERFLOW";
else
{ stk[top-pos+1]=value;
}*/
}
void main()
{ clrscr();
int n,i;
cout<<"\nEnter the size of stack:\n";
cin>>n;
again:
cout<<"Enter your choice:";
cout<<"1.PUSH\n";
cout<<"2.POP\n";
cout<<"3.PEEP\n";
cout<<"4.CHANGE\n";
cin>>i;
switch(i)
{
case 1:PUSH(n);
break;
case 2:POP();
break;
case 3:PEEP();
break;
case 4:CHANGE();
break;
default:exit(0);
}
cout<<" Do u want to continue(Y=1/N=0):";
int x;
cin>>x;
if(x==1)
{
goto again;
}
else
{
exit(0); }
getch();
}
/* output:-
Enter the size of stack:
3
Enter your choice:1.PUSH
2.POP
3.PEEP
4.CHANGE
1
Enter the element to be inserted:4
Do u want to continue(Y=1/N=0):1
Enter your choice:1.PUSH
2.POP
3.PEEP
4.CHANGE
1
Enter the element to be inserted:5
Do u want to continue(Y=1/N=0):1
Enter your choice:1.PUSH
2.POP
3.PEEP
4.CHANGE
1
Enter the element to be inserted:6
Do u want to continue(Y=1/N=0):1
Enter your choice:1.PUSH
2.POP
3.PEEP
4.CHANGE
4
Enter the position u want to change value:2
Enter the value to be change:55
Do u want to continue(Y=1/N=0):1
Enter your choice:1.PUSH
2.POP
3.PEEP
4.CHANGE
3
Enter the element position u want to search:2
Required element:55 Do u want to continue(Y=1/N=0):
0
*/
c programming language example programs
c sample code Compare last instance of two strings