-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_queue.c
More file actions
53 lines (49 loc) · 1.14 KB
/
print_queue.c
File metadata and controls
53 lines (49 loc) · 1.14 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
// The printer Queue uses the queue concept to store the list of files they get to print in the printer. Write a program to print the first file in the printer Queue. If the no of print files is more than the print queue size, it should say “overflow” otherwise print the name of the first file.
// Input:
// Queue size n , no of inputs m and input file names
// Output: names of the first file in the queue to be printed or overflow
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max 20
struct node
{
char st[max];
struct node *next;
} *f = NULL, *r = NULL;
typedef struct node queue;
void enqueue(char *st)
{
queue *newnode = malloc(sizeof(queue));
newnode->next = NULL;
strcpy(newnode->st, st);
if (r == NULL)
{
f = r = newnode;
}
else
{
r->next = newnode;
r = newnode;
}
}
int main()
{
int t, n;
scanf("%d", &t);
scanf("%d", &n);
int i = t;
while (i--)
{
char st[max];
scanf("%s", st);
enqueue(st);
}
if (n > t)
printf("Overflow\n");
else
{
printf("%s", f->st);
}
return 0;
}