CS3413/Assignment4/round_robin.c

54 lines
1.8 KiB
C
Raw Normal View History

2023-10-24 13:50:05 -03:00
#include <stdio.h>
#include "lib/queue.h"
#define MAX_USERNAME_LENGTH 100
int QUANTUM;
typedef struct Summary {
char username[MAX_USERNAME_LENGTH];
int last_time;
} Summary;
Queue* input_queue() {
Queue* queue = createQueue();
scanf("%d", &QUANTUM);
char username[MAX_USERNAME_LENGTH];
char job;
int arrival_time, duration;
while(scanf("%s100 %c %d %d", username, &job, &arrival_time, &duration) != EOF) {
Process *process = createProcess(username, job, arrival_time, duration);
enqueue(queue, process);
}
return queue;
}
void simulation(Queue* queue) {
printf("Time\tJob\n");
int time = 0;
Queue *sim_queue = createQueue();
//Take note of all usernames at the start, and then create an array of summary
//When a job finishes, take note of its username, and then go through the array of summary and find the username
//Once you find the username, assign the last_time to the current time.
//TODO: May need to change as the summary should be sorted by username arrival time
//Go through list and check for arrival times at current time
//If arrival time is at current time, add to sim_queue
//If there is nothing in sim_queue, print -
//If there is something in sim queue, store the process in a variable, so we can check the quantum
//If the quantum is 0, then we need to dequeue the process and enqueue it again
//If the quantum is not 0, then we need to print the process and decrement the quantum
//If the process is done, then we need to print the process and dequeue it
//If the process is not done, then we need to print it and leave the queue alone
//Once we reach the point where time is greater than the last arrival time, we need to check if sim_queue is empty
//Once sim_queue is empty, we need to break out of the loop
}
int main() {
Queue* input = input_queue();
}