- Recursive traversal adds every animal in the dingo family to the zoo.

Animal brutus = new Dingo("Brutus", 3, 36.0, Gender.Male);
Animal coco = new Dingo("Coco",7, 38.3, Gender.Female);
coco.AddChild(brutus);
Animal toby = new Dingo("Toby", 4, 42.5, Gender.Male);
Animal steve = new Dingo("Steve", 4, 41.1, Gender.Male);
Animal maggie = new Dingo("Maggie", 7, 34.8, Gender.Female);
maggie.AddChild(toby);
maggie.AddChild(steve);
Animal lucy = new Dingo("Lucy", 7, 36.5, Gender.Female);
Animal ted = new Dingo("Ted", 7, 39.7, Gender.Male);
Animal bella = new Dingo("Bella", 10, 40.2, Gender.Female);
bella.AddChild(coco);
bella.AddChild(maggie);
bella.AddChild(lucy);
bella.AddChild(ted);
List<Animal> tempList = new List<Animal>();
tempList.Add(bella);
tempList.Add(new Dingo("Max", 12, 46.9, Gender.Male));
This time when the breakpoint hits, ensure that the animal in the list is just Brutus (Coco's child).
Ensure that all of the dingos were added to the zoo. Note that the dingos are added in the order of the parents, then their children, then the children's children.


Then call the WalkTree method and pass in the animal and an empty string.
animal 1
first child of animal 1
first child of first child of animal 1
second child of first child of animal 1
second child of animal 1
first child of second child of animal 1
animal 2Run the "show children" command for Bella. The result should look like the image below.

Quick Sort: The quick sort find a pivot value (often the first, last or middle value in the list) and moves other items in the list to the appropriate side of the pivot value. It then uses recursion to sort the smaller lists on either side of the now correctly placed pivot value. Because it is recursive, the algorithm continually finds pivot values and sorts the ever-smaller sections of the overall list until the entire list is sorted.
5.5.3 How to Use Quick Sort


The pointer values will change throughout the method while the index values will stay the same.
Animal pivotAnimal = animals[(leftIndex + rightIndex) / 2];
// Gets the animal between the index points.// "Woah there's something bigger than you in this section".// "Woah there's something smaller than you in this section."// "We have to get these animals in the right section! Let's swap them! Then let's close in on a smaller section."// "Have we completed this section or do we need to check again?"// If the LEFT "section" of the list isn't sorted, sort it.// If the RIGHT "section" of the list isn't sorted, sort it.Toby should swap with Ted because Toby doesn't have an animal with a weight higher than his on the left of him BUT has an animal with a weight lower than his on the right of him.
This time the leftPointer is higher than the rightPointer, indicating that the section from 6 to 8 is sorted correctly.
Since the leftPointer is less than the rightIndex the Sort method will be called with a new set of indexes (section).
Ensure that the animals are sorted from lightest to heaviest, the swap count is 8 and the compare count is 21.

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 8 and the compare count should be 20.
© 2026 Northcentral Technical College