There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:
Sorting is always in ascending order, from "small" to "large". But what is small and what is large is defined by the compareTo or the compare method.
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
henry leu wrote:
If obj1 should APPEAR BEFORE obj2 in a sorted list, then we return a negative number. (No swap)
If obj1 should APPEAR AFTER obj2 in a sorted list, then we return a positive number. (Swap)
If we don't care which object comes first (because they might be equal), then we return zero. (no swap)
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
I am not convinced that is right. I think it would be more like what follows, but I think even that isn't accurate.henry leu wrote:. . .
Positive: swap the element
Negative: no swap
Zero: no swap
A Comparator (as does the Comparable interface) imposes an ordering on objects of a particular type. The word “ordering” is used in the sense the mathematicians would use is.If obj1 should APPEAR BEFORE obj2 in a sorted list, then we return a negative number. (No swap)
If obj1 should APPEAR AFTER obj2 in a sorted list, then we return a positiv default e number. (Swap)
If we don't care which object comes first (because they might be equal), then we return zero. (no swap)
. . .
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |