Skip to content
Snippets Groups Projects
Commit c8ffa361 authored by AlifIhsan Syauqi's avatar AlifIhsan Syauqi
Browse files

Adjusted

parent bb8734c3
No related branches found
No related tags found
No related merge requests found
#include "list_1 (1).h"
// Gimme the number of elements of L
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment