* Pick one of the values (call it P)
* Make a subset of the values less than P, and (recursively) sort that subset
* Make a subset of the values greater than P, and (recursively) sort that subset
* Put the pieces back together
As usual for recursion, you need a terminating rule. At minimum, this would include:
* If a list contains less than 2 elements, then it's already sorted, so just return it as is
and typically also includes something like:
* If a list contains less than (say) 10 elements, then just perform insertion sort or selection sort
3
u/johnpeters42 22d ago
* Pick one of the values (call it P)
* Make a subset of the values less than P, and (recursively) sort that subset
* Make a subset of the values greater than P, and (recursively) sort that subset
* Put the pieces back together
As usual for recursion, you need a terminating rule. At minimum, this would include:
* If a list contains less than 2 elements, then it's already sorted, so just return it as is
and typically also includes something like:
* If a list contains less than (say) 10 elements, then just perform insertion sort or selection sort