We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Note: the relative order of the array must remain unchange. That is {4,2,1,6,5} -> {2,1,4,6,5}
voidprintf_arr(int*arr,intl,intr){for(inti=l;i<(r+1);i++){printf("%d ",arr[i]);}printf("\n");}// Note: The order of the array must remain unchangedintpartition(int*arr,intl,intr){int*res_arr=(int*)malloc((r+1)*sizeof(int));intpivot=arr[l];intptr=l,idx=l;for(inti=l;i<(r+1);i++){if(arr[i]<pivot)res_arr[ptr++]=arr[i];}idx=ptr;res_arr[ptr++]=pivot;for(inti=l;i<(r+1);i++){if(arr[i]>pivot)res_arr[ptr++]=arr[i];}for(inti=l;i<ptr;i++){arr[i]=res_arr[i];}free(res_arr);returnidx;}voidmy_quick_sort(int*arr,intl,intr){if(l<r){intidx=partition(arr,l,r);my_quick_sort(arr,l,idx-1);my_quick_sort(arr,idx+1,r);printf_arr(arr,l,r);}}voidquickSort(intar_size,int*ar){// Complete this functionmy_quick_sort(ar,0,ar_size-1);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Quicksort 2 - Sorting
You are viewing a single comment's thread. Return to all comments →