-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20_Multiple_stack_array.c
More file actions
127 lines (112 loc) · 1.98 KB
/
20_Multiple_stack_array.c
File metadata and controls
127 lines (112 loc) · 1.98 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <stdio.h>
#include<stdlib.h>
#define SIZE 50
int ar[SIZE],data;
int top1 = 0;
int top2 = SIZE-1;
void push_stack1 ()
{
printf("\nenter data :");
scanf("%d",&data);
if (top1 < (top2 - 1))
{
ar[top1] = data;
top1++;
}
else
{
printf ("Stack Full! Cannot Push\n");
}
}
void push_stack2 ()
{
printf("\nenter data :");
scanf("%d",&data);
if (top1 < top2 - 1)
{
ar[top2] = data;
top2--;
}
else
{
printf ("Stack Full! Cannot Push\n");
}
}
void pop_stack1 ()
{
if (top1 >= 0)
{
int popped_value = ar[top1];
top1--;
printf ("%d is being popped from Stack 1\n", popped_value);
}
else
{
printf ("Stack Empty! Cannot Pop\n");
}
}
void pop_stack2 ()
{
if (top2 < SIZE)
{
int popped_value = ar[top2];
top2++;
printf ("%d is being popped from Stack 2\n", popped_value);
}
else
{
printf ("Stack Empty! Cannot Pop\n");
}
}
void display()
{
int i,j;
printf("stack 1:\n");
for (i = 0; i<top1; i++)
{
printf ("%d ", ar[i]);
}
printf ("\n");
printf("stack 2:\n");
for (j = SIZE-1; j>top2 ; j--)
{
printf ("%d ", ar[j]);
}
printf ("\n");
}
int main()
{
int ar[SIZE];
int i,ch;
int num_of_ele;
printf ("We can push a total of 50 values\n");
while(1)
{
printf("1. push in stack 1\n2. push in stack 2\n3. pop from stack 1\n4. pop from stack 2\n5.display\n6. exit\nenter choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
push_stack1 ();
break;
case 2:
push_stack2 ();
break;
case 3:
pop_stack1 ();
break;
case 4:
pop_stack2 ();
break;
case 5:
display();
break;
case 6:
exit (0);
default:
printf("wrong choice");
break;
}
}
return 0;
}