I have a list of Fruit structs called basket. Each Fruit struct has a name (a string) and a calories (an integer). I would like to sort basket so that:
The
Fruits with the highestcaloriesappear first. For example, a fruit with 500 calories appears before a fruit with 400 calories.If two
Fruits have equalcalories, theFruitwhosenamecomes first alphabetically comes first, ignoring case. For example, given two fruits with equal calories, one named "banana" will come before one named "Citrus".
The definition of Fruit is not something I control so I'd prefer a solution which doesn't involve mixing anything into Fruit or changing it. Is this possible?