IMPLEMENTATION OF ADT - STACK
SOURCE CODE:
#include “iostream.h”
#include “conio.h”
class stack
{
public:
int top,ele,s[20];
stack();
void push();
void pop();
void list();
void display();
};
stack::stack()
{
top=0;
}
void stack::push()
{
clrscr();
cout << "PUSH OPERATION \n"; if(top==10) cout << "The Stack Is Full"; else { cout << "Enter The Number Of Elements To Be Entered : "; int m; cin >> m;
cout << "Enter The Elements \n"; for(int i=0;i
s[top]=ele;
top=top+1;
}
display();
}
}
void stack::pop()
{
clrscr();
cout << "POP OPERATION \n"; if(top==0) cout << "The Stack Is Empty"; else { top=top-1; cout << "The Popped Element Is : " << top="=" i="0;i" x="stack();">> ch;
switch(ch)
{
case 1:
x.push();
break;
case 2:
x.pop();
break;
case 3:
x.list();
break;
default:
cout << "Your Choice Is Wrong"; } cout << "Do You Want To Continue? "; cin >> c;
}while(c='Y'c='y');
}
OUTPUT
STACK OPERATION
MENU
1.PUSH
2.POP
3.LIST
Enter Your Choice : 1
PUSH OPERATION
Enter The Number Of Elements To Be Entered : 4
Enter The Elements
1
2
3
4
The Elements Are
1
2
3
4
Do You Want To Continue? Y
STACK OPERATION
MENU
1.PUSH
2.POP
3.LIST
Enter Your Choice : 2
POP OPERATION
The Popped Element Is : 4
The Index Of The Popped Element Is : 3
The Elements Are
1
2
3
Do You Want To Continue? Y
STACK OPERATION
MENU
1.PUSH
2.POP
3.LIST
Enter Your Choice : 3
LIST OPERATION
The Elements Are
1
2
3
Do You Want To Continue? N