To arrange a collection of items
in some specified order. The items -
records in a file or
data structures in memory - consist of one or more
fields or
members. One of these fields is designated as the "sort key"
which means the records will be ordered according to the value
of that field. Sometimes a sequence of key fields is
specified such that if all earlier keys are equal then the
later keys will be compared. Within each field some ordering
is imposed, e.g. ascending or descending numerical, lexical ordering, or date.
Sorting is the subject of a great deal of study since it is a
common operation which can consume a lot of computer time.
There are many well-known sorting algorithms with different
time and space behaviour and programming
complexity.
Examples are
quicksort,
insertion sort,
bubble sort,
heap sort, and tree sort. These employ many different
data structures to store sorted data, such as arrays,
linked lists, and binary trees.