+ 11

Does quicksort use pointers in cpp?

22nd Mar 2017, 7:59 PM
StillSoulβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€
StillSoulβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€ - avatar
7 Answers
+ 18
You could, but ideally why would you? Most implementations use some sort of recursive function. void quickSort(int arr[], int left, int right) { int i = left, j = right; int tmp; int pivot = arr[(left + right) / 2]; /* partition */ while (i <= j) { while (arr[i] < pivot) i++; while (arr[j] > pivot) j--; if (i <= j) { tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; i++; j--; } }; /* recursion */ if (left < j) quickSort(arr, left, j); if (i < right) quickSort(arr, i, right); }
23rd Mar 2017, 11:32 PM
Ace
Ace - avatar
+ 17
@StillSoul: I believe that is O(NΒ²) worst case, O(N*log(N)) best and average case
24th Mar 2017, 2:53 PM
Ace
Ace - avatar
+ 17
No the recursive function is the one that has the high cost. see this link: http://quiz.geeksforgeeks.org/quick-sort/
24th Mar 2017, 3:07 PM
Ace
Ace - avatar
+ 8
....rt!
24th Mar 2017, 2:56 PM
StillSoulβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€
StillSoulβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€ - avatar
+ 8
better than bubble atleast
24th Mar 2017, 3:11 PM
StillSoulβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€
StillSoulβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€ - avatar
+ 5
right...recursion is better O() decreases significantly..it becomes O[log N] rt?
24th Mar 2017, 12:05 PM
StillSoulβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€
StillSoulβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€ - avatar
+ 3
Quicksort is a sorting technique, used to sort the elements​ of array in ascending or descending order. Normally you don't need to use pointers. But yeah you can also use pointers to implement Quicksort!!
23rd Mar 2017, 6:11 AM
Harjeet Singh
Harjeet Singh - avatar