Algorithm Implementation/Sorting/Heapsort

Basic heapsort
With an existing heap data structure, a basic heapsort is simple to implement.

Common Lisp
This is an almost direct translation of the heapsort pseudocode found at Wikipedia, taking a list of scalars as input.

In-place heapsort
The disadvantage of the basic method is its memory requirement; it requires both an array and a heap of size n.

If we realize that heaps can be stored as arrays, a solution presents itself: Store the heap in the same array as the unsorted/sorted elements.

C
This is a fast implementation of heapsort in C, adapted from Numerical Recipes in C but designed to be slightly more readable and to index from 0.

Ocaml
This implementation is in place and uses the imperative features of the language such as loops and mutable reference cells.

Example of use: # let a = [|4;45;67;4;2;2;3;4;6;8;9;9;7;5;4;32;3;4;5;6;6;4;3;2;3;5;7;8;9;8;7;6;54|] in heapsort a (Array.length a); a;; - : int array = [|2; 2; 2; 3; 3; 3; 3; 4; 4; 4; 4; 4; 4; 5; 5; 5; 6; 6; 6; 6; 7; 7; 7; 8; 8; 8; 9; 9; 9; 32; 45; 54; 67|]