-
Notifications
You must be signed in to change notification settings - Fork 0
/
double stack in a single array.c
131 lines (129 loc) · 1.5 KB
/
double stack in a single array.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
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
128
129
130
131
#include<stdio.h>
#include<stdlib.h>
#define maxsize 4
int stack[maxsize];
void push1();
void push2();
void pop1 ();
void pop2 ();
void disp1();
void menu();
void disp2();
int top1=-1;
int top2=maxsize;
int i;
int main ()
{
while(1)
menu();
}
void menu()
{
int ch;
printf("\n ----------------------Menu------------------------ \n 1. Push1 \n2. push 2\n3. pop1 \n4. pop2\n5. disp1 \n6 disp2 \n7. exit ");
printf("\n choise the option");
scanf("%d",&ch);
switch(ch)
{
case 1:push1();
break;
case 2: push2();
break ;
case 3: pop1();
break ;
case 4: pop2();
break ;
case 5: disp1();
break ;
case 6: disp2();
break ;
case 7: exit(1);
break;
default:printf("\nwrong input");
}
}
void push1()
{
int item;
if(top1==top2-1)
{
printf("stack is full ");
}
top1=top1+ 1;
printf("\n enter the number ");
scanf("%d",&item);
stack[top1]=item;
}
void push2()
{
int item;
if(top2==top1+1)
{
printf("\n stack is full");
}
else
{
top2--;
printf("\nenter the number");
scanf("%d",&item);
stack[top2]=item;
}
}
void pop1()
{
int x;
if(top1==-1)
{
printf("\n empty ");
}
else
{
x=stack[top1];
printf("%d is pop from the stack",x);
top1--;
}
}
void pop2()
{
int y ;
if(top2==maxsize)
{
printf(" stack is full");
}
else
{
y=stack[top2];
printf("%d is pop from the stack",stack[top2]);
top2++;
}
}
void disp1()
{
int i;
if (top1==-1)
{
printf("\n empty");
}
else
{
for( i=0;i<=top1;i++)
{
printf("\n\n%d",stack[i]);
}
}
}
void disp2()
{
int i;
if(top2==maxsize)
{
printf("\n empty");
}
else
{
for(i=top2;i<maxsize;i++)
{
printf("\n%d",stack[i]);
}
}
}