diff --git a/LES TA DES TACHES/include/list_2.h b/LES TA DES TACHES/include/list_2.h index d3d09b9a55ff8785f3b4ede6f971578790f51958..597c7404657f30b42b3d0a41ade8ce3be400c056 100644 --- a/LES TA DES TACHES/include/list_2.h +++ b/LES TA DES TACHES/include/list_2.h @@ -1,4 +1,3 @@ - #include "list_1 (1).h" // Gimme the number of elements of L diff --git a/LES TA DES TACHES/src/list_2.c b/LES TA DES TACHES/src/list_2.c index 7f58ca3785261768bc40a8cecd3e4eeb6751ca4b..d2cd4a5de8d0ed1d359a9827ced83257af06e651 100644 --- a/LES TA DES TACHES/src/list_2.c +++ b/LES TA DES TACHES/src/list_2.c @@ -78,7 +78,7 @@ void ordered_insert(struct list_t * L, void * data, int (*cmp_ptrf)()){ } } -// Elements with data less than pivot go into val_inf; the rest go into val_sup. +// Elements qui sont moins = val_inf et le reste val_sup. static void partition(list_t * L, elmlist_t * pivot, list_t * val_inf, list_t * val_sup, int (*cmpFct)(void*, void*)) { for (elmlist_t * cur = L->head; cur != NULL; cur = cur->suc) { if (cmpFct(get_data(cur), get_data(pivot)) < 0) @@ -92,26 +92,36 @@ void quick_sort(list_t * L, int (*cmpFct)(void*, void*)) { assert(L && cmpFct); if (L->numelm > 1) { - // Remove pivot from L. + elmlist_t * pivot = get_head(L); - L->head = get_suc(pivot); // Remainder of L. + L->head = get_suc(pivot); pivot->pred = NULL; pivot->suc = NULL; + + /** @note + * La listes des données inférieures à pivot + * La listes des données supérieures à pivot + */ list_t * val_inf_pivot = new_list(); list_t * val_sup_pivot = new_list(); - // Partition sur les restes de la liste - partition(L, pivot, val_inf_pivot, val_sup_pivot, cmpFct); - - // Free the original list's elements (they have been reinserted in the new lists) + /** @note Déplacement des données de L dans val_inf_pivot et val_sup_pivot */ + partition(L,pivot,val_inf_pivot,val_sup_pivot,cmpFct); + + /** @note On supprimer les éléments de L sans supprimer ni L ni les jobs */ elmlist_t * S; - for (elmlist_t * E = L->head; E; E = S) { + for(elmlist_t * E = L->head; E; E = S){ S = E->suc; free(E); } - // Process elements less than pivot. + /** @note + * Si la partie inf est vide alors L commence par le pivot + * Sinon on tri grâce à cmpFct la partie inf puis on ajoute en queue le pivot + */ + + if (is_empty(val_inf_pivot)) { L->head = pivot; L->tail = pivot; @@ -126,7 +136,10 @@ void quick_sort(list_t * L, int (*cmpFct)(void*, void*)) { L->tail = pivot; L->numelm += 1; } - // Process elements greater than or equal to the pivot. + /** @note + * Si la partie sup n'est pas vide alors + * On la trie puis on la concatène à la partie inf + */ if (!is_empty(val_sup_pivot)) { quick_sort(val_sup_pivot, cmpFct); val_sup_pivot->head->pred = pivot; @@ -187,7 +200,7 @@ void quick_sort(list_t * L, int (*cmpFct)(void*, void*)) { -// View list + void view_list(list_t * L, void (*ptrf)()) { assert(L && ptrf); elmlist_t * curr = L->head; @@ -197,7 +210,7 @@ void view_list(list_t * L, void (*ptrf)()) { } } -// Return a ptr to element which data is key else NULL +// Return un ptr vers element else NULL void find(list_t * L, void ** ptrKey, int (*cmpFct)(), void (*delFct)()) { assert(L && ptrKey && cmpFct); elmlist_t * curr = L->head;