-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmulti_stack.c
More file actions
119 lines (106 loc) · 1.72 KB
/
multi_stack.c
File metadata and controls
119 lines (106 loc) · 1.72 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
#include<stdio.h>
#include<conio.h>
#define MAX_X 5
#define MAX_Y 5
int topx=-1;
int topy=10;
void push_x(int *stack)
{
int info;
if(topx>=(MAX_X-1))
{ printf("\n\nStack OverFlow");
return;
}
else
{ printf("\n\nEnter The info To Push");
scanf("%d",&info);
topx++;
stack[topx]=info;
}}
void push_y(int *stack)
{
int info;
if(topy<=(MAX_Y))
{
printf("\n\nStack OverFlow");
return;
}
else
{
printf("\n\nEnter The info To Push");
scanf("%d",&info);
topy--;
stack[topy]=info;
}
}
void pop_x(int *stack)
{ if(topx==-1)
{
printf("Stack X is Underflow");
return;
}
else
{
printf("Item Poped from stack X is:%d\n",stack[topx]);
topx--;
}
}
void pop_y(int *stack)
{ if(topy==10)
{printf("Stack y is Underflow");
return;
}
else
{ printf("Item Poped from stack Y is:%d\n",stack[topy]);
topy++;
}}
void display_x(int *stack)
{
int i;
if(topx==-1)
{
printf("Stack X is Empty");
return;
}
else
{ for(i=topx;i>=0;i--)
{printf("%d,",stack[i]);}
printf("\n");
}}
void display_y(int *stack)
{
int i;
if(topy==10)
{printf("Stack Y is Empty");
return;}
else
{for(i=topy;i<=9;i++)
{
printf("%d,",stack[i]);
}
printf("\n");
} }
main()
{ int choice;
char ch;
int stack[MAX_X+MAX_Y];
do
{ printf("1.Push_X\n2.Push_Y\n");
printf("\n3.Pop_X\n4.Pop_Y\n");
printf("\n5.Display_X\n6.Display_Y\n");
printf("\n7.Exit");
printf("\n\nEnter Choice");
scanf("%d",&choice);
switch(choice)
{
case 1: push_x(stack);break;
case 2: push_y(stack);break;
case 3: pop_x(stack);break;
case 4: pop_y(stack);break;
case 5: display_x(stack);break;
case 6: display_y(stack);break;
case 7: break;
default: printf("Wrong Option...");
}
}while(choice!=7);
}