A similar question was asked previously about "when" the recursion happens in inheritance and I'm struggling to wrap my head around it.
How does the program ever reach parent[1] if create family is recursively called on parent[0]? wouldn't the call keep happening on parent[0] and reducing the generations until it the condition was no longer met?
person *create_family(int generations)
{
// TODO: Allocate memory for new person
person *p = malloc(sizeof(person));
// Generation with parent data
// generations keeps track of where we are in the family tree
if (generations > 1)
{
// TODO: Recursively create blood type histories for parents
p->parents[0] = create_family(generations -1);
p->parents[1] = create_family(generations -1);
// TODO: Randomly assign child alleles based on parents
int randomIndex0 = rand() % 2;
int randomIndex1 = rand() % 2;
p->alleles[0] = p->parents[0]->alleles[randomIndex0];
p->alleles[1] = p->parents[1]->alleles[randomIndex1];
}
// Generation without parent data
else
{
// TODO: Set parent pointers to NULL
p->parents[0] = NULL;
p->parents[1] = NULL;
// TODO: Randomly assign alleles
p->alleles[0] = random_allele();
p->alleles[1] = random_allele();
}
// TODO: Return newly created person
return p;
}