Start with three numbers: X Y Z step 1) if (X > Y) then swap (X,Y) // now X <= Y step 2) if (Y > Z) then swap (Y,Z) // now Y <= Z and X <= Z too step 3) if (X > Y) then swap (X,Y) // now X<=Y<=Z Proof that after step 2, Y <= Z and X <= Z: After step 1, X <= Y. It is obvious that Y <= Z after step 2. To see that also X <= Z after step 2, note the following: In step 2, two things can happen: A) The test shows that Y <= Z and the swap is not performed. In that case, since X <= Y was made true in step 1, we have X <= Y and Y <= Z, which implies that X <= Z, by transitivity. B) The test shows that Y > Z, and the swap IS performed. Now X <= Z follows from the fact that X <= Y after step 1, and the swap made Y the NEW value of Z. === Example One: start with: 3 2 1 after step 1: 2 3 1 after step 2: 2 1 3 after step 3: 1 2 3 === Example Two: start with: 3 1 2 after step 1: 1 3 2 after step 2: 1 2 3 after step 3: 1 2 3 === Example Three: start with: 2 1 3 after step 1: 1 2 3 after step 2: 1 2 3 after step 3: 1 2 3 === Example Four: start with: 2 3 1 after step 1: 2 3 1 after step 2: 2 1 3 after step 3: 1 2 3