forked from kabirthakkar/Hkfst2k21
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoubleStack.c
114 lines (107 loc) · 1.5 KB
/
DoubleStack.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
#include<stdio.h>
#include<conio.h>
void push1(int[],int *,int *,int);
void push2(int[],int *,int *,int);
int pop1(int[],int *,int *);
int pop2(int[],int *,int *);
void main()
{
clrscr();
int stack[10];
int top1=-1;
int top2=10;
int value,i,num,c,choice;
printf("Enter 1 to push\n");
printf("Enter 2 to pop\n");
printf("Enter 3 to display\n");
scanf("%d",&choice);
if(choice==1)
{
printf("Enter 1 to push from top1\n");
printf("Enter 2 to push from top2\n");
scanf("%d",&c);
if(c==1)
{
printf("Enter the number of values to be pushed\n");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("Enter the value to be pushed\n");
scanf("%d",&value);
push1(stack,&top1,&top2,value);
}
printf("New Stack:\n");
if(num>10)
{
for(i=9;i>=0;i--)
{
printf("%d\n",stack[i]);
}
}
else
{
for(i=top1;i>=0;i--)
{
printf("%d\n",stack[i]);
}
}
}
if(c==2)
{
printf("Enter the number of values to be pushed\n");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("Enter the value to be pushed\n");
scanf("%d",&value);
push2(stack,&top1,&top2,value);
}
printf("New Stack:\n");
if(num>10)
{
for(i=0;i<10;i++)
{
printf("%d\n",stack[i]);
}
}
else
{
for(i=top2;i<=9;i++)
{
printf("%d\n",stack[i]);
}
}
}
}
if(choice==2)
{
}
if(choice==3)
{
for(i=9;i>=0;i--)
{
printf("%d",stack[i]);
}
}
getch();
}
void push1(int s[],int * top1,int * top2,int val)
{
if(*top1+1==*top2)
{
printf("Overflow\n");
return;
}
*top1=*top1+1;
s[*top1]=val;
}
void push2(int s[],int * top1,int * top2,int val)
{
if(*top2-1==*top1)
{
printf("Overflow\n");
return;
}
*top2=*top2-1;
s[*top2]=val;
}