-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStack_p
More file actions
88 lines (82 loc) · 1.36 KB
/
Stack_p
File metadata and controls
88 lines (82 loc) · 1.36 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
83
84
85
86
87
88
#include <stdio.h>
int stack[100],n,i,top=-1,choice=0;
void Push();
void Pop();
void display();
int main() {
printf("\nenter the no. of elements");
scanf("%d",&n);
while(choice!=4)
{
printf("\n1.Push\n 2.Pop\n3.display\n4.Exit");
printf("\nenter choice");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
Push();
break;
}
case 2:
{
Pop();
break;
}
case 3:
{
display();
break;
}
case 4:
{
break;
}
default:
printf("\ninvalid");
};
}
return 0;
}
void Push()
{
int item;
if(top==n)
{
printf("\noverflow");
}
else
{
printf("\nenter the item");
scanf("%d",&item);
top=top+1;
stack[top]=item;
}
}
void Pop()
{
int item;
if(top==-1)
{
printf("\nempty");
}
else
{
top=top-1;
}
}
void display()
{
if(top==-1)
{
printf("\nstack empty");
}
else
{
for(int i=top;i>=0;i--)
{
printf("\n list of elements are");
printf("%d\n",stack[i]);
}
}
}