//void sort_quicksort(Dane &wekt, int poczatek, int koniec ) void sort_quicksort(Dane &wekt, int left, int right) { int l=left; int r=right-1; int size=right-left; if (size > 1) { //int pivot = wekt.Wektor[rand() % size + l]; int pivot=wekt.Wektor[(left+right)/2]; while (l<r) { while (wekt.Wektor[r]>pivot && r>l) r--; while (wekt.Wektor[l] < pivot && l<=r) l++; if (l<r) { wekt.Zamien_elementy(wekt, l, r); l++; } } sort_quicksort(wekt, left, l); sort_quicksort(wekt, r, right); } //cout<<wekt<<endl; }
void sort_linked_list(struct linked_list_t *linked_list, comparator cmp) { /* allocats space for the index accumulator to be used durring the sequence iteration */ size_t index; /* allocates space for the linear sequence of values to be created for the sorting algorithm execution and then retrieves the target size for it */ void **sequence; size_t sequence_size = linked_list->size; /* allocates space for the next and current node node, sets the current node to the linked list first node */ struct linked_list_node_t *next_node; struct linked_list_node_t *current_node = linked_list->first; /* converts the linked list into a linear sequence of values then uses the sequence for sorting execution */ to_sequence_linked_list(linked_list, &sequence); sort_quicksort(sequence, 0, sequence_size, cmp); /* iterates over the sequence to update the proper elements in the linked list (reuses current nodes) */ for(index = 0; index < sequence_size; index++) { /* retrieves the next node */ next_node = current_node->next; /* updates the current node value with the current value in the sequence */ current_node->value = sequence[index]; /* sets the current node as the next node */ current_node = next_node; } /* releases the created sequence */ FREE(sequence); }