-
Notifications
You must be signed in to change notification settings - Fork 287
/
Copy pathstack all operation
106 lines (92 loc) · 1.79 KB
/
stack all operation
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
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <stdio.h>
int size=10;
struct stack
{
int top;
int a[10];
};
void push(struct stack *p,int data)
{
if(p->top==size-1)
{
printf("stack is over flow right now");
}
else
{
p->top++;
p->a[p->top]=data;
}
}
void pop(struct stack *p)
{
if(p->top==-1)
{
printf("stack is empty right now");
}
else{
int y=p->top--;
printf("%d\n",p->a[y]);
}
}
void peep(struct stack *p,int index)
{
if(p->top==-1)
{
printf("stack is empty right now");
}
else
{
printf("%d\n",p->a[p->top-index+1]);
}
}
void display(struct stack *p)
{
if(p->top==-1)
{
printf("stack is empty right now");
}
else
{
for(int i=p->top;i>=0;i--)
{
printf("%d\n",p->a[i]);
}
}
}
int main()
{
struct stack s;
s.top=-1;
int n;
int w;
int e;
while(1)
{
printf("-----------------------------------------------\n");
printf("enter the number \n 1)push operation \n 2) peep operation \n 3)pop operatin \n 4) display \n 5) exit \n");
printf("-----------------------------------------------\n");
scanf("%d",&n);
switch(n)
{
case 1:
printf("enter the number\n");
scanf("%d",&w);
push(&s,w);
break;
case 2:
printf("enter the index in between 1 to 10\n");
scanf("%d",&e);
peep(&s,e);
break;
case 3:
pop(&s);
break;
case 4:
display(&s);
break;
case 5:
exit(0);
}
}
return 0;
}