QuickSort
QuickSort can be done either in a functional or imperative style.
functional style
In functional language, we use an algorithm based on a single recursive function:
- pick a "pivot" element to compare against
- filter the rest into elements which are smaller, and elements which are =>
- return the concatenation of:
- the result of calling myself on the smaller list
- the pivot element
- the result of calling myself on the larger list
imperative style
In an imperative language like C, we essentially do the same except we swap the elements in-place rather than creating new lists.