An n-ary tree can
get a little hairy sometimes:
Just follow the steps
Note: Functions over descendant family trees must work correctly on both the tree part AND the list part.
Recall that INFINITY is a double that represents infinity. It requires #include <math.h> to appear at the top of the program.
2. Develop the function countProperDescendents which consumes a parent and produces the number of descendents, not including the parent.
3. Develop the function generationDescendents which consumes a parent and a generation number and produces a list of all information about descendents in that generation.
4. Develop the function truncate which consumes a parent and a generation number and produces a parent that does not have any descendents in that generation (and thus, obviously, subsequent generations.)
5. Write a function countGenerations which counts the number of generations in a descendant family tree.
6. Generalize howFarRemoved so it takes an eye color argument and does not always check for blue-eye descendents.
These notes are primarily for my sake, but I don’t see any reason to hide them from you.
family trees were ancestor based
hard to learn about children
let's switch the arrows
but now, people can have multiple children...
parent is info, list of children
count-blue-eyed : parent -> number
has-old-and-blue? : parent number -> boolean [has a blue eyed descedent born before a given data]
count-descendents : parent -> number
descendents : parent -> ListOfInfo
averageAge : parent -> number
truncateTree : parent number -> parent [removes everyone after a generation]
advanced-ages : parent -> parent [update ages by 1]