-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpicking_up_last_job.c
More file actions
44 lines (41 loc) · 988 Bytes
/
picking_up_last_job.c
File metadata and controls
44 lines (41 loc) · 988 Bytes
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
// Computer handles multiuser, multiprogramming environment and time-sharing environment. In this environment a system (computer) handles several jobs at a time; to handle these jobs the concept of a queue is used. Write a program to pick up the last job in the queue of a multi-tasking environment.
// Input: queue size n and list of jobs
// Output: name of the last job
#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;
scanf("%d", &t);
while (t--)
{
char st[max];
scanf("%s", st);
enqueue(st);
}
printf("%s", r->st);
return 0;
}