Copyright (C) 1994, Digital Equipment Corp.
\index{sorting!arrays}
GENERIC INTERFACEArraySort (Elem);
WhereElem.Tis a type that is not an open array type andElemcontains
PROCEDURE Compare(a, b: Elem.T): [-1 .. 1];Comparemust define a total order. Any parameter mode may be used.
PROCEDURE Sort(VAR a: ARRAY OF Elem.T; cmp := Elem.Compare);
Sort the elements ofausing the order defined bycmp.
END ArraySort.
Sort(a, cmp) permutes the elements of a such that:
FIRST(a) <= i < j <= LAST(a)
implies
cmp(a[i], a[j]) <= 0.
The algorithm used is QuickSort:
\begin{itemize}
\item It is not stable.
\item On average, it requires O(N ln N) comparison and assignment
operations. In the worst case it may require O(N*N) operations.
\end{itemize}
For an expanded description of QuickSort, see \cite{Sedgewick:Alg}.