2021-04-20 16:12:44 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2021-04-20 16:50:27 +00:00
|
|
|
#include <string.h>
|
2021-04-20 16:12:44 +00:00
|
|
|
#include "jobs.h"
|
|
|
|
|
|
|
|
void ajouter(list* l_ptr, int pid, int id) {
|
|
|
|
|
|
|
|
cell* new_cell = malloc(sizeof(*new_cell));
|
|
|
|
|
|
|
|
new_cell->pid = pid;
|
|
|
|
new_cell->id = id;
|
|
|
|
|
|
|
|
if (*l_ptr == NULL) {
|
|
|
|
new_cell->next = NULL;
|
|
|
|
} else {
|
|
|
|
new_cell->next = *l_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
*l_ptr = new_cell;
|
|
|
|
|
|
|
|
printf("[%d] %d\n", id, pid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void supprimer(list* l_ptr, int pid) {
|
|
|
|
|
|
|
|
cell* cursor = *l_ptr;
|
|
|
|
|
|
|
|
if (cursor->pid == pid) {
|
|
|
|
cell* cursor2free = cursor;
|
|
|
|
*l_ptr = cursor->next;
|
|
|
|
free(cursor2free);
|
|
|
|
} else {
|
|
|
|
while (cursor->next != NULL) {
|
|
|
|
if (cursor->next->pid == pid) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
cursor = cursor->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cell* cursor_next = cursor->next->next;
|
|
|
|
free(cursor->next);
|
|
|
|
cursor->next = cursor_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void afficher(list* l_ptr) {
|
|
|
|
|
|
|
|
cell* cursor = *l_ptr;
|
|
|
|
|
|
|
|
while (cursor != NULL) {
|
|
|
|
printf("[%d] %d\n", cursor->id, cursor->pid);
|
|
|
|
cursor = cursor->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void initialiser(list* l_ptr) {
|
|
|
|
*l_ptr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void liberer(list* l_ptr) {
|
|
|
|
free(*l_ptr);
|
|
|
|
*l_ptr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int est_vide(list l_ptr) {
|
|
|
|
return l_ptr == NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int contiens(list* l_ptr, int pid) {
|
|
|
|
|
|
|
|
cell* cursor = *l_ptr;
|
|
|
|
|
|
|
|
while (cursor != NULL) {
|
|
|
|
if (cursor->pid == pid) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
cursor = cursor->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|