You are viewing a single comment's thread. Return to all comments →
C++;
//Quicksort 2 - Sorting #include <iostream> using namespace std; int subFunc_quickSort_partition(int *arr, int startIndex, int endIndex){ int pivot = arr[startIndex]; int pivotIndex = startIndex; for(int i=startIndex+1 ; i<=endIndex ; i++){ if(arr[i]<pivot){ int tempNum = arr[i]; for(int j=i ; j>pivotIndex ; j--) arr[j] = arr[j-1]; arr[pivotIndex] = tempNum; pivotIndex++; } } return pivotIndex; } void func_quickSort(int *arr, int startIndex, int endIndex){ if(startIndex>=endIndex) return; int pivotindex = subFunc_quickSort_partition(arr,startIndex,endIndex); func_quickSort(arr,startIndex,pivotindex-1); func_quickSort(arr,pivotindex+1,endIndex); for(int a=startIndex ; a<=endIndex ; a++) cout << arr[a] << " "; cout<<endl; } int main (){ int arraySize = 0; cin >> arraySize; int *arr = new int[arraySize]; for(int a=0 ; a<arraySize ; a++) cin >> arr[a]; func_quickSort(arr,0,arraySize-1); }
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 →
C++;