-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack_to_Queue.c
More file actions
93 lines (80 loc) · 1.28 KB
/
Copy pathStack_to_Queue.c
File metadata and controls
93 lines (80 loc) · 1.28 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
#include<stdio.h>
#define MAX 5
int q[MAX],s[MAX];
int f=-1, r=-1, top=-1;;
int isFull();
int isEmpty();
void push(int);
int pop();
int enqueue(int);
int main()
{
int val;
printf("Input Data in stack(5): ");
for(int i=0 ; i<MAX; i++)
{
scanf("%d",&val);
push(val);
}
printf("Output showing in queue)(5): ");
for(int i=0 ; i<MAX; i++)
{
printf("%d ",enqueue(pop()));
}
return 0;
}
int isFull()
{
if(top + 1 == MAX)
return 1;
else
return 0;
}
int isEmpty()
{
if(top == -1)
return 1;
else
return 0;
}
void push(int val)
{
if(isFull())
printf("Stack Overflow.");
else
{
s[++top] = val;
}
}
int pop()
{
int data;
if(isEmpty())
printf("Stack Overflow.");
else
{
data = s[top--];
return data;
}
}
int enqueue(int val)
{
if(f == -1 && r == -1)
{
f=r=0;
q[r] = val;
return q[r];
}
else
{
r=(r+1)%MAX;
q[r]=val;
return q[r];
}
}
<!DOCTYPE html>
<html>
<body>
<h2>Project Done by © Nushrat Jaben Aurnima. All Rights Reserved .</h2>
</body>
</html>