- The console and zoo expose the structures needed to request and report a sort.
this.animals = new List<Animal>()
{
new Chimpanzee("Bobo", 10, 128.2, Gender.Male),
new Chimpanzee("Bubbles", 3, 103.8, Gender.Female),
new Dingo("Spot", 5, 41.3, Gender.Male),
new Dingo("Maggie", 6, 37.2, Gender.Female),
new Dingo("Toby", 0, 15.0, Gender.Male),
new Eagle("Ari", 12, 10.1, Gender.Female),
new Hummingbird("Buzz", 2, 0.02, Gender.Male),
new Hummingbird("Bitsy", 1, 0.03, Gender.Female),
new Kangaroo("Kanga", 8, 72.0, Gender.Female),
new Kangaroo("Roo", 0, 23.9, Gender.Male),
new Kangaroo("Jake", 9,153.5, Gender.Male),
new Ostrich("Stretch", 26, 231.7, Gender.Male),
new Ostrich("Speedy", 30, 213.0, Gender.Female),
new Platypus("Patti", 13, 4.4, Gender.Female),
new Platypus("Bill", 11, 4.9, Gender.Male),
new Platypus("Ted", 0, 1.1, Gender.Male),
new Shark("Bruce", 19, 810.6, Gender.Female),
new Shark("Anchor", 17, 458.0, Gender.Male),
new Shark("Chum", 14, 377.3, Gender.Male),
new Squirrel("Chip", 4, 1.0, Gender.Male),
new Squirrel("Dale", 4, 0.9, Gender.Male)
};Look at the diagram below to understand how the command structure will work.

Return null in methods that have a return for now.

Write the following message to the console when an exception is caught:
Sort command must be entered as: sort [sort type] [sort by -- weight or name]."SORT TYPE: " + commandWords[1].ToUpper()
"SORT BY: " + commandWords[2].ToUpper()It should look similar to below:
"SWAP COUNT: " + [SortResult variable here].SwapCount"For example, if the values of the index parameters are 2 and 6, then the animal in the 6 position in the list should move to the 2 position, and the animal in the 2 position should move to the 6 position.
Bubble Sort: The bubble sort loops through a list. With each loop it compares two adjacent values; if the values are out of order it will swap the two values. This forces larger values to "bubble" up to the end of the list and then stops the value from being compared to again.

By Swfung8 (Own work) [CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0) or GFDL (http://www.gnu.org/copyleft/fdl.html)], via Wikimedia Commons
5.3.2 How to Use Bubble Sortint swapCounter = 0;
// use a for loop to loop backward through the list
for (int i = animals.Count - 1; i > 0; i--)
{
Console.WriteLine(i);
}Your output should look like the image below. The list of animals has 21 animals in it so the starting number is 20 and it decrements with each loop.

// loop forward as long as the loop variable is less than the outer loop variable
for (int j = 0; j < i; j++)
{
}The outer loop should begin at 20 and the inner loop should begin at 0. While the outer loop is at 20, the inner loop will execute until it reaches 20 and then stops.
If it does, Swap the animals, passing in the animals list, j, and j + 1.
It should be 128.2 (the weight of the first animal in the list, Bobo).
It should be 103.8 (the weight of the second animal in the list, Bubbles).

Hover over the Weight properties of the logic check. The first animal should be 128.2 (Bobo) and the second animal should be 41.3 (Spot).
Bobo should continue to "bubble up" until he hits Jake and then the logic check will fail.
He has "bubbled" all the way to the top because he is the heaviest.
Now that we know Bruce is the heaviest animal, we don't care about him and the outer loop decreases to 19.
Your console should look like the output below with the animals sorted in ascending weights and 108 swaps made.


It is the same as the algorithm for weight, but it compares the name values instead of the weight values.
5.3.4 How to Compare StringsThe animals should be sorted by name in ascending order and the swap count should be 108.
Selection Sort: The selection sort is similar to the bubble sort but improves upon it by making a maximum of one swap on each pass through the list instead of multiple swaps. The sort's outer loop looks at each item in the list to find out if an item has the minimum value of the unsorted items; if it doesn't have the minimum value, it will be swapped with whatever item does have the minimum value.
Sonny Jr via http://sonnyjr.me/tag/selection-sort/


The animals should be in ascending order by weight with a swap count of 16.


It is the same as the algorithm for weight, but it compares the name values instead of the weight values.
The swap count should be 20.
© 2026 Northcentral Technical College