-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackoperation.cpp
More file actions
82 lines (79 loc) · 1.04 KB
/
stackoperation.cpp
File metadata and controls
82 lines (79 loc) · 1.04 KB
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
#include<stdio.h>
#include<process.h>
#include<stdlib.h>
#define MAX 5
int top=-1,stack[MAX];
void push();
void pup();
void traverse();
main()
{
int ch;
while(1)
{
printf("***stack menu***");
printf("\n\n\n1.push\n2.pop\n3.traverse\n4.exit\n");
printf("enter ur choice");
scanf("%d",&ch);
switch(ch)
{
case 1:
push();
break;
case 2:
pup();
break;
case 3:
traverse();
break;
case 4:
exit(0);
default:
printf("\n wrong choice!!!!");
}
}
}
void push()
{
int val;
if(top==MAX-1)
{
printf("\n is full");
}
else
{
printf("\nenter the element to push:");
scanf("%d",&val);
top=top+1;
stack[top]=val;
}
}
void pup()
{
if(top==-1)
{
printf("\nstack is empty");
}
else
{
printf("\ndeleted item is %d",stack[top]);
top=top-1;
}
return;
}
void traverse()
{
int i;
if(top==-1)
{
printf("\nstavk is empty!!!!");
}
else
{
printf("\nstack is.......\n");
for(i=top;i>=0;i--)
{
printf("%d\n",stack[i]);
}
}
}