aboutsummaryrefslogtreecommitdiff
path: root/impls/qsort.cpp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2025-10-27 00:28:51 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2025-10-27 00:28:51 +0000
commite3863557f5762735bc2c911f94a96a84dae2d8f5 (patch)
tree261ddedad7fa20511e667426d31a763b8e3c86ff /impls/qsort.cpp
parent8ee90f0d06baf15f4779c705c1e2863d586ba375 (diff)
downloadalgorithms-e3863557f5762735bc2c911f94a96a84dae2d8f5.tar.gz
algorithms-e3863557f5762735bc2c911f94a96a84dae2d8f5.tar.bz2
algorithms-e3863557f5762735bc2c911f94a96a84dae2d8f5.zip
Some cleanup of qsort and vec
Diffstat (limited to 'impls/qsort.cpp')
-rw-r--r--impls/qsort.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/impls/qsort.cpp b/impls/qsort.cpp
index d3e8c1d..a230456 100644
--- a/impls/qsort.cpp
+++ b/impls/qsort.cpp
@@ -33,13 +33,12 @@ void quicksort(int *arr, int arr_size)
print_arr(arr, arr_size);
printf("\n");
#endif
- // Optimisation: for small arr_size, a different sort like the
- // bubble sort may be better, instead of initialising new stack
- // frames.
+ // TODO Optimisation: for small arr_size, a different sort like the bubble
+ // sort may be better, instead of initialising new stack frames.
if (arr_size < 2)
return;
- // Optimisation: Use some heuristics to figure out a better pivot
- // than some constant choice of element.
+ // TODO Optimisation: Use some heuristics to figure out a better pivot than
+ // some constant choice of element.
int pivot = 0;
int pivot_value = arr[0];
for (int i = 1; i < arr_size; ++i)
@@ -57,13 +56,12 @@ void quicksort(int *arr, int arr_size)
print_arr(arr, arr_size);
printf("\n");
#endif
- // Optimisation: Use a stack to do this instead of recursion.
+ // TODO Optimisation: Use a stack to do this instead of recursion.
//
- // This algorithm is similar to a pre order traversal/dfs, in this
- // case on an array where left and right partition are children
- // nodes to the original array node. Also with recursion there's a
- // real risk for very large ARR_SIZE of running out of space in the
- // call stack.
+ // This algorithm is similar to a pre order traversal/dfs, in this case on an
+ // array where left and right partition are children nodes to the original
+ // array node. Also with recursion there's a real risk for very large
+ // ARR_SIZE of running out of space in the call stack.
if (pivot != 0)
quicksort(arr, pivot);
if (pivot < arr_size - 1)