Add working but shit a4 implementation

This commit is contained in:
2023-10-26 15:58:58 -03:00
parent a6ad3f17a1
commit ac641e6e46
6 changed files with 118 additions and 43 deletions

View File

@ -1,9 +1,9 @@
#ifndef NODE_H
#define NODE_H
#ifndef PROCESS_H
#define PROCESS_H
typedef struct Process {
struct process *prev_elem;
struct process *next_elem;
struct Process *prev_elem;
struct Process *next_elem;
char *username;
char job;
int arrival_time;
@ -14,4 +14,4 @@ Process *createProcess(char *username, char job, int arrival_time, int duration)
void destroyProcess(Process *node);
#endif //NODE_H
#endif //PROCESS_H

View File

@ -60,14 +60,16 @@ Process *dequeue(Queue *queue) {
if (queue->end == NULL) { // If the queue is empty, return NULL
return NULL;
}
Process *temp = queue->end; // Store the end of the queue for returning later
Process *temp = queue->end; // Store the end of the queue for returning later
if (queue->size == 1) { // If the queue has one element, set the start and end to NULL
queue->start = NULL;
queue->end = NULL;
queue->size--;
return temp;
}
queue->end = queue->end->prev_elem; // Set the end to the previous element
queue->end->next_elem = NULL; // Set the next element of the new end to NULL
if (queue->end == NULL) { // If the queue is empty, set the start to NULL
queue->start = NULL;
}
queue->end->next_elem = NULL; // Set the next element of the new end to NULL
temp->prev_elem = NULL; // The dequeued element should not point to anything
queue->size--;