/* Scheduling two resources. */ #include "queue.h" #include #include /* The basic queue routines. */ int isempty(QUEUE q) { return (q.front == NULL); } DATA vfront(QUEUE q) { return (q.front -> d); } void dequeue(QUEUE *q, DATA *x) { LINK temp = q -> front; if (!isempty(*q)) { *x = temp -> d; q -> front = temp -> next; free(temp); } else printf("Empty queue.\n"); } void enqueue(QUEUE *q, DATA x) { LINK temp; temp = malloc(sizeof(ELEMENT)); temp -> d = x; temp -> next = NULL; if (isempty(*q)) q -> front = q -> rear = temp; else { q -> rear -> next = temp; q -> rear = temp; } } main() { QUEUE a = {NULL, NULL}, b = {NULL, NULL}; int c, cnt_a = 0, cnt_b = 0; DATA pid; while ((c = getchar()) != EOF) { if (c == 'A' || c == 'a') { scanf("%d", &pid); enqueue(&a, pid); } else if (c == 'B' || c == 'b') { scanf("%d", &pid); enqueue(&b, pid); } } printf("\nA's schedule\n"); while (!isempty(a)) { dequeue(&a, &pid); printf("JOB %d is %d\n", ++cnt_a, pid); } printf("\nB's schedule\n"); while (!isempty(b)) { dequeue(&b, &pid); printf("JOB %d is %d\n", ++cnt_b, pid); } }