-
Notifications
You must be signed in to change notification settings - Fork 0
/
3. Implementation Of Queue.c
188 lines (158 loc) · 3.69 KB
/
3. Implementation Of Queue.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/**********************************************************************************************************
TITLE: Program to create Queue of Students taking admission in a college using static memory allocation.
**********************************************************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 20
typedef struct
{
int reg_no;
char branch[SIZE];
}student;
//Nested Structure
typedef struct
{
student s[SIZE];//queue of students
int rear,front;
}queue;
void enqueue(queue *p,int x,char *n) //to insert elements
{
if(p->rear==SIZE-1)
printf("Queue is Full\n");
else
{
p->rear++;
p->s[p->rear].reg_no=x; //inserted registration no
strcpy(p->s[p->rear].branch,n);//inserted branch
if(p->front==-1)
p->front=0;
}
}
student dequeue(queue *p)
{
student x;
if(p->front==-1)
{
printf("Queue is Empty\n");
x.reg_no=0;
strcpy(x.branch,"null");
return x;
}
else
{
x.reg_no=p->s[p->front].reg_no;
strcpy(x.branch,p->s[p->front].branch);
if(p->front==p->rear)
{
p->front=-1;
p->rear=p->front;
}
else
p->front++;
return x;
}
}
void display(queue q)
{
int i;
if(! isempty(q))//if queue is not empty,equivalent condition is isempty(q)==0
{
for(i=q.front;i<=q.rear;i++)
{
printf("Student %d :\nRegistration number: %d\nBranch: %s\n",i+1,q.s[i].reg_no,q.s[i].branch);
}
}
else
{
printf("Queue is Empty");
}
}
int isempty(queue q)
{
if(q.front==-1)
return 1;
else
return 0;
}
int main()
{
queue q1;
student y;
int i,choice;
char ch;
q1.front=q1.rear=-1;
do
{
printf("Enter the choice: 1.Enqueue 2.Dequeue 3.Display\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the Student's Registration number:\n");
scanf("%d",&y.reg_no);
printf("Enter the Student's branch:\n");
scanf("%s",y.branch);
enqueue(&q1,y.reg_no,y.branch);
break;
case 2 :
y=dequeue(&q1);
printf("Turn of the following student to submit the form:\n%d and %s \n",y.reg_no,y.branch);
break;
case 3:
printf("Students who have not submitted the form:\n");
display(q1);
break;
default: printf("Enter proper choice:\n");
}
printf("Do you want to continue:\n");
scanf("%s",&ch);
printf("\n\n");
}while(ch=='y'||ch=='Y');
return 0;
}
/**********************************************************************************************************
OUTPUT:
Enter the choice: 1.Enqueue 2.Dequeue 3.Display
1
Enter the Student's Registration number:
8960
Enter the Student's branch:
Computer
Do you want to continue:
y
Enter the choice: 1.Enqueue 2.Dequeue 3.Display
1
Enter the Student's Registration number:
8942
Enter the Student's branch:
Mechanical
Do you want to continue:
y
Enter the choice: 1.Enqueue 2.Dequeue 3.Display
1
Enter the Student's Registration number:
9000
Enter the Student's branch:
Production
Do you want to continue:
y
Enter the choice: 1.Enqueue 2.Dequeue 3.Display
2
Turn of the following student to submit the form:
8960 and Computer
Do you want to continue:
y
Enter the choice: 1.Enqueue 2.Dequeue 3.Display
3
Students who have not submitted the form:
Student 2 :
Registration number: 8942
Branch: Mechanical
Student 3 :
Registration number: 9000
Branch: Production
Do you want to continue:
n
Process returned 0
**********************************************************************************************************/