diff --git a/QuickSort b/QuickSort new file mode 100755 index 0000000..7fb5189 Binary files /dev/null and b/QuickSort differ diff --git a/QuickSort.cpp b/QuickSort.cpp index 35dcb22..ad21d1a 100644 --- a/QuickSort.cpp +++ b/QuickSort.cpp @@ -23,11 +23,21 @@ int partition (int arr[], int low, int high){ } void quickSort(int arr[], int low, int high){ - if (low < high){ - int pi = partition(arr, low, high); - quickSort(arr, low, pi - 1); - quickSort(arr, pi + 1, high); - } + int pa; + while(low < high) + { + pa = partition(arr, low, high); + if(pa - 1 < high - pa) //recurse into the smaller halve + { + quickSort(arr, low, pa - 1); + low = pa + 1; + } + else{ + quickSort(arr, pa + 1, high); + high = pa - 1; + } + } + } void printArray(int arr[], int size){ diff --git a/QuickSort.o b/QuickSort.o new file mode 100644 index 0000000..9128dce Binary files /dev/null and b/QuickSort.o differ