public class Item implements Comparable<Item> {
private int weight;
public Item(int w) { weight = w; }
public int compareTo(Item other) {
return this.weight - other.weight;
}
}What sort order does this produce?
- A
descending by weight
- B
alphabetical
- C
random
- Dcheck_circle
ascending by weight
Explanation
Returning this.weight - other.weight gives ascending order.