Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * arr - array da ordinare
- * start - L'inzio della sequenza che dev'essere ordinata.
- * end - La fine della sequenza che dev'essere ordinata.
- */
- void quickSortRecursive(int arr[], int start, int end){
- if(start < end){
- int indice_pivot = partition( arr, start, end );
- quickSortRecursive(arr, start, indice_pivot-1); //Autoattivazione lato sinistro
- quickSortRecursive(arr, indice_pivot+1, end); //Autoattivazione lato destro
- }
- }
- //Restituisce l'indice del pivot ed effettua gli scambi
- int partition (int arr[], int start, int end){
- int x = arr[end];
- int i = (start - 1);
- for (int j = start; j <= end- 1; j++){
- if (arr[j] <= x){ //confronta ogni elemento sinistro con l'ultimo elemento dell'array/subarray
- i++;
- swap (&arr[i], &arr[j]);
- }
- }
- swap (&arr[i + 1], &arr[end]);
- return (i + 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement