Finish a4
This commit is contained in:
@ -8,6 +8,7 @@ typedef struct Process {
|
||||
char job;
|
||||
int arrival_time;
|
||||
int duration;
|
||||
int finish_time;
|
||||
} Process;
|
||||
|
||||
Process *createProcess(char *username, char job, int arrival_time, int duration);
|
||||
|
@ -16,27 +16,24 @@
|
||||
* And when you dequeue, you are exiting from the end of the line
|
||||
*/
|
||||
|
||||
//TODO: Refactor
|
||||
int contains(Queue *queue, char *job) {
|
||||
Process *current = queue->start;
|
||||
int contains(Queue *queue, char *username) {
|
||||
Process *current = queue->end;
|
||||
while (current != NULL) {
|
||||
if (strcmp(current->username, job) == 0) {
|
||||
if (strcmp(current->username, username) == 0) {
|
||||
return true;
|
||||
}
|
||||
current = current->next_elem;
|
||||
current = current->prev_elem;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO: Refactor
|
||||
Process *search(Queue *queue, char *job) {
|
||||
Process *current = queue->start;
|
||||
|
||||
Process *search(Queue *queue, char *username) {
|
||||
Process *current = queue->end;
|
||||
while (current != NULL) {
|
||||
if (strcmp(current->username, job) == 0) {
|
||||
if (strcmp(current->username, username) == 0) {
|
||||
return current;
|
||||
}
|
||||
current = current->next_elem;
|
||||
current = current->prev_elem;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -54,7 +51,6 @@ void enqueue(Queue *queue, Process *process) {
|
||||
queue->size++;
|
||||
}
|
||||
|
||||
|
||||
// WARNING: Returns a pointer to a process that is not in the queue, it is your responsibility to free it
|
||||
Process *dequeue(Queue *queue) {
|
||||
if (queue->end == NULL) { // If the queue is empty, return NULL
|
||||
@ -75,17 +71,13 @@ Process *dequeue(Queue *queue) {
|
||||
queue->size--;
|
||||
return temp;
|
||||
}
|
||||
|
||||
//TODO: Refactor
|
||||
void printList(Queue *queue) {
|
||||
Process *current = queue->start;
|
||||
Process *current = queue->end;
|
||||
while (current != NULL) {
|
||||
// printf("%s %d\n", current->username, current->duration);
|
||||
current = current->next_elem;
|
||||
printf("%s\t%d\n", current->username, current->finish_time);
|
||||
current = current->prev_elem;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Refactor
|
||||
int stop(Queue *queue) {
|
||||
Process *current = queue->end;
|
||||
while (current != NULL) {
|
||||
|
@ -10,9 +10,9 @@ typedef struct Queue {
|
||||
int size;
|
||||
} Queue;
|
||||
|
||||
int contains(Queue *queue, char *job);
|
||||
int contains(Queue *queue, char *username);
|
||||
|
||||
Process *search(Queue *queue, char *job);
|
||||
Process *search(Queue *queue, char *username);
|
||||
|
||||
void enqueue(Queue *queue, Process *process);
|
||||
|
||||
|
Reference in New Issue
Block a user