-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.stack_arr.c
More file actions
113 lines (98 loc) · 1.34 KB
/
1.stack_arr.c
File metadata and controls
113 lines (98 loc) · 1.34 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//Stack implementation using Arrays
#include<stdio.h>
int arr[50],top=0,s;
void push();
void pop();
void display();
main()
{
int c,t;
printf("\nEnter the size of stack : ");
scanf("%d",&s);
do
{
printf("\n Menu \n1.Insert\n2.Delete\n3.Display\n");
scanf("%d",&t);
switch(t)
{
case 1 : push();
break;
case 2 : pop();
break;
case 3 : display();
break;
default : printf("Wrong entry !!\n");
}
printf("Do you want to continue/exit 1/0 ?\n");
scanf("%d",&c);
}
while(c);
}
void push()
{
if(top==s)
printf("\nStack overflow\n");
else
{
printf("Enter the element : ");
scanf("%d",&arr[top]);
top=top+1;
}
}
void pop()
{
if(top==0)
printf("Stack is underflow");
else
top=top-1;
}
void display()
{
int i;
if(top==0)
printf("Stack empty");
else
{
printf("The stack is \t");
for(i=0;i<top;i++)
printf("%d\t",arr[i]);
printf("\n");
}
} //End of Program
/*
OUTPUT
---------------
Enter the size of stack : 2
Menu
1.Insert
2.Delete
3.Display
1
Enter the element : 25
Do you want to continue/exit 1/0 ?
1
Menu
1.Insert
2.Delete
3.Display
1
Enter the element : 32
Do you want to continue/exit 1/0 ?
1
Menu
1.Insert
2.Delete
3.Display
3
The stack is 25 32
Do you want to continue/exit 1/0 ?
1
Menu
1.Insert
2.Delete
3.Display
1
Stack overflow
Do you want to continue/exit 1/0 ?
0
*/