Round-robin
user_0531932
c_cpp
2 years ago
901 B
4
Indexable
int empty(struct queue_t *q) { if (q == NULL) return 1; return (q->size == 0); } void enqueue(struct queue_t *q, struct pcb_t *proc) { /* TODO: put a new process to queue [q] */ if (q->size < MAX_QUEUE_SIZE) { int t = q->size; q->proc[t] = proc; q->size++; } } struct pcb_t *dequeue(struct queue_t *q) { /* If the queue is empty, return NULL. */ if (q->size == 0) { return NULL; } //printf("%s\n", "Here"); /* Get the head element from the front of the queue. */ struct pcb_t *head = q->proc[0]; /* Shift all the elements to the left by one position. */ for (int i = 0; i < q->size - 1; i++) { q->proc[i] = q->proc[i+1]; } /* Decrement the size of the queue. */ q->size--; /* Return the head element. */ return head; }
Editor is loading...