-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSTACKMAN.CPP
79 lines (70 loc) · 1.27 KB
/
STACKMAN.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
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
#include<iomanip.h>
#include<string.h>
#include<math.h>
#include<dos.h>
#include<fstream.h>
#include<string.h>
#include<stdlib.h>
void push(int list[], int &top, int n)
{
if(top==9)
cout<<"buffer overflow";
delay(2000);
else
list[++top]=n;
}
void pop(int list[], int top)
{
cout<<"deleted element is ="<<list[top--];
delay(3000);
}
int is_empty(int top)
{
if(top==-1)
return(1);
else
return(0);
}
void display(int list[], int top)
{
int i;
for(i=top;i>=0;i--)
cout<<list[i]<<endl;
}
void main()
{
system("cls");
int list[10];
int top=-1;
int num, opt;
do
{
cout<<"\t\t\toperations on stack\n\n\3 1.\tpush\n\4 2.\tpop\n\5 3.\tdisplay\n\6 4.\texit\n\n\nenter option\n";
cin>>opt;
switch(opt)
{
case 1: cout<<"enter value to be entered\n";
cin>>num;
push(list, top, num);
break:
case 2: if(is_empty(top))
cout<<"buffer underflow\n";
else
pop(list, top);
getch();
break;
case 3: display(list, top);
getch();
clrscr;
case 4:cout<<"press any key to exit";
break;
default: cout<<"wrong choice press any key to return to main menu";
}
}while(opt!=4);
getch();
exit(0);
}