Way-way more is true than stated by the OP's Question (or even the earlier answers).
Let notation $\ a/b\ $ stand for an ordered pair $ a\ $ and $\ b\ $ of non-negative integers that are relatively prime.
Such pairs $\ a/b\ $ are interpreted as positive rational numbers except for the single case of $\ 1/0\ $ that is interpreted as $\ \infty.\ $
Let two such pairs, $\ A/B\ $ and $\ a/b\ $ be called neighbors (in this order!) $\ \Leftarrow:\Rightarrow\ $ their determinant is $\ 1,\ $ i.e.
$$ A\cdot b-B\cdot a\ =\ 1. $$
For instance
$$ \frac11\quad\frac12 $$
are neighbors.
Let's start with an arbitrary pair of neighbors as the top row of table $\ T(A/B\,\ a/b),\ $ and lets obtain the next rows of the table (in a Pascal triangle manner) by applying the median operation in order to obtain a new row from the last row by:
$$ A/B\quad a/b $$
$$ A/B\quad(A+a)/(B+b)\quad a/b $$
$$ A/B\quad(2\!\cdot\! A+a)/(2\!\cdot\! a+b)\quad(A+a)/(B+b)
\quad (A+2\!\cdot\! a)/(B+2\cdot b)\quad a/b $$
etc.
Obviously, each two consecutive elements of arbitrary row of the table are neighbors. The following two basic theorems hold (have you seen the second one in print?):
Let $\ X/x\ $ be a pair of relatively prime non-negative integers such that $\ A/a\ge X/x\ge B/b,\ $ i.e. $\ A\cdot x\ge a\cdot X\ $ and $\ X\cdot b\ge x\cdot B.\ $ Then $\ X/x\ $ appears in a row of the table (hence in allm next rows too).
Arbitrary pair of neighbors, $\ X/x\quad Y/y\ $, such that
$$ A/a\ \ge\ X/x\ >\ Y/y\ \ge\ B/B $$
appears as consecutive elements of a row in the table exactly one time.
Remarks
- Table $\ T(A/a\,\ B/b)\ $ is a subtable of table $\ T(1/0\,\ 0/1).\ $ This last table represents all non-negative rational numbers as well as $\ \infty:=1/0.$
- Table $\ T(1/0\,\ 0/1)\ $ corresponds to the general special monoid generated by the two "two by two" 0-1 triangular matrices; it immediately tells you that it is a free monoid in two generators, and it tells you about everything there is about this monoid. Indeed, given a pair of neighbors, the median produces two pairs of neighbors that can be equivalently defined by applying the two triangular matrices to the given pair of neighbors.
(I am not able to recall the name of the author of table $\ T(1/\, 0/1).\ $ I seem to remember that this name was mentioned in a small monograph by Knuth)
- Table $\ T(1/0\,\ 0/1)\ $ may serve as a foundation for the elementary diophantine (rather better than the otherwise impressive Farey sequence) -- this table is in a simple way directly related to the continued fractions.