-
Notifications
You must be signed in to change notification settings - Fork 0
/
SA.cpp
93 lines (82 loc) · 1.68 KB
/
SA.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include<iostream.h>
#include<conio.h>
using namespace std;
int STACK[MAX],TOP;
void initStack(){
TOP=-1;
}
int isEmpty(){
if(TOP==-1)
return 1;
else
return 0;
}
int isFull(){
if(TOP==MAX-1)
return 1;
else
return 0;
}
void push(int num)
{
if(isFull()){
cout<<"STACK is FULL.\n";
return;
}
++TOP;
STACK[TOP]=num;
cout<<num<<" has been inserted.\n";
}
void display()
{
int i;
if(isEmpty()){
cout<<"STACK is EMPTY.\n";
return;
}
for(i=TOP;i>=0;i--){
cout<<STACK[i]<<" ";
}
cout<<endl;
}
void pop(){
int temp;
if(isEmpty()){
cout<<"STACK is EMPTY.\n";
return;
}
temp=STACK[TOP];
TOP--;
cout<<temp<<" has been deleted.\n";
}
void main()
{
int num;
initStack();
char ch;
do{
int a;
cout<<"Chosse \n1.push\n"<<"2.pop\n"<<"3.display\n";
cout<<"Please enter your choice: ";
cin>>a;
switch(a)
{
case 1:
cout<<"Enter an Integer Number: ";
cin>>num;
push(num);
break;
case 2:
pop();
break;
case 3:
display();
break;
default :
cout<<"An Invalid Choice!!!\n";
}
cout<<"Do you want to continue ? ";
cin>>ch;
}while(ch=='Y'||ch=='y');
getch();
}