-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_operation.c
107 lines (88 loc) · 1.53 KB
/
stack_operation.c
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
#include<stdio.h>
#define SIZE 50
void push();
void pop();
void display();
struct stack
{
int data[SIZE];
int top;
}s;
int main()
{
s.top=-1;
int choice;
printf("\n---------------------------------------------\n");
printf("\n\t 1-->push\n");
printf("\n\t 2-->pop\n");
printf("\n\t 3-->display\n");
printf("\n\t 4-->exit\n");
printf("\n---------------------------------------------\n");
while(1)
{
printf("\n enter choice ");
scanf("%d",&choice);
switch(choice)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
return;
break;
}
}
return ;
}
void push()
{
if(s.top==SIZE-1)
{
printf("\n NO Space available ");
}
else
{
s.top=s.top+1;
printf("\n enter the number you want to enter ");
scanf("%d",&s.data[s.top]);
}
return;
}
void pop()
{
int num;
if(s.top==-1)
{
printf("\n stack is empty ");
}
else
{
num=s.data[s.top];
printf("poped out element is %d \n",s.data[s.top]);
s.top=s.top-1;
}
return ;
}
void display()
{
int i;
printf("\n current position of stack is \n");
if(s.top==-1)
{
printf("\n stack is empty ");
}
else
{
for(i=s.top;i>=0;i--)
{
printf("%3d",s.data[i]);
}
}
return;
}