-
Notifications
You must be signed in to change notification settings - Fork 0
/
stackusingqueuecpy.txt
74 lines (58 loc) · 971 Bytes
/
stackusingqueuecpy.txt
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
#include <stdio.h>
#define MAX 50
int queue1[MAX],queue2[MAX];
int front1 = -1,rear1 = -1,front2 = -1,rear2 = -1;
int count;
void enqueue1(int x)
{
if(front1==-1)
front1 = 0;
queue1[++rear1] = x;
printf("queue1 %d\n",queue1[rear1]);
}
void enqueue2(int x)
{
if(front2==-1)
front2 = 0;
queue2[++rear2] = x;
printf("queue2 %d\n",queue2[rear2]);
}
int dequeue1()
{
int x = queue1[front1++];
return x;
}
int dequeue2()
{
int x = queue2[front2++];
return x;
}
void push(int x)
{
if(rear1==MAX-1)
printf("overflow\n");
else
{
enqueue1(x);
count++;
}
}
void pop()
{
while(front1<=rear1)
enqueue2(dequeue1());
while(front2<rear2)
enqueue1(dequeue2());
printf("The popped element is %d\n",dequeue2());
}
int main()
{
push(10);
push(20);
push(100);
pop();
pop();
pop();
push(10756);
pop();
}