posted 6 years ago
Hi Neil,

to simplify writing I set a1 = new A(1) and respectively a2, a3.

Now, when cs.add(a1) is performed, the objects a1 and a3 are compared. Actually it doesn't matter if compare(a1,a3) or

compare(a3,a1) is inoked, since in any case the comparison yields a1 < a3. For:

compare(a1,a3) yields -1, meaning a1 < a3.

compare(a3,a1) yields +1, meaning a3 > a1, which is equivalent to a1 < a3.

So after adding a1, the order of cs is {a1,a3}.

When adding a2, the three elements a1, a2, a3 are compared, yielding the order {a1,a2,a3}.

Hope it helps.

SCJP 5 (98%) - SCBCD 5 (98%)