A linear ordering on a finite collection of objects may be described as follows: each object has exactly one immediate predecessor object and one immediate successor object with two exceptions: A first object has no predecessor and a last object has no successor.
A linear ordering is also known as a total ordering or a simple ordering.
A binary relationship $ a \leq b $ (read as a precedes or equals b) between two objects is said to be a linear ordering if:
We will say that $ a < b $ (read as a precedes b) if $ a \leq b $ and $ a \ne b $.
Given $ n $ objects which have a linear ordering, we may order them $ a_1, a_2, a_3, \ldots, a_n $ such that $ a_1 \leq a_2 \leq a_3 \leq \ldots \leq a_n $ as is shown in Figure 1.
Figure 1. The ordering of 10 objects.
A linear ordering between to objects a and b may be implicitly defined through the operation a <= b which returns a Boolean value. In this case, the relationship depends only on the objects themselves. In C++, the operator<= may be overloaded as is demonstrated in this code block which compares two rational numbers:
bool operator<= ( Rational const &p, Rational const &q ) { return p.numerator*q.denominator <= q.numerator*p.denominator; }
For example, if a container has the values 24, 3, 13, 36, 5, 8, 30, 12, 17, and 29, they may be ordered as shown in Figure 2.
Figure 2. The ordering of 10 specific integers.
Alternatively, the programmer can explicitly define the linear ordering: one object precedes another because it was explicitly placed in that location. The most common example of such an explicit linear ordering is a string: the string "Hello world!" is an ordered sequence of twelve characters.
Operations which may be performed on a container with objects which satisfy an equivalence relation include:
Given an implicit linear ordering, it is possible to pose additional operations:
Given an explicit linear ordering, other operations include:
Any text editor must store the contents of a file in a linear order and any edit to the text will changed the linear ordering.