1. Code ------- #include #include #include struct Cat *getCat(void); struct Date { int day; int month; int year; }; struct Cat { struct Date dob; char name[20]; char father[20]; char mother[20]; struct Cat *next; struct Cat *previous; }; int main() { struct Cat *first = NULL; struct Cat *current = NULL; struct Cat *last = NULL; char more = '\0'; int i =0; for(i =0;i<5 ;i++ ) { current = getCat(); if(first == NULL){ first = current; last = current; }else { last->next = current; current->previous = last; last = current; } } while (current != NULL) { printf("\n%s was born %d/%d/%d, and has %s and %s as parents.", current->name, current->dob.day, current->dob.month, current->dob. year, current->father, current->mother ); last = current; /* Save pointer to enable memory to be freed */ current = current->previous; /* current points to previous list */ free(last); } } struct Cat *getCat(void) { struct Cat *temp; temp = (struct Cat*) malloc(sizeof(struct Cat)); printf("\nEnter the name of the person: "); scanf("%s", temp -> name ); printf("\nEnter %s's date of birth (day month year); ", temp->name); scanf("%d %d %d", &temp->dob.day, &temp->dob.month, &temp->dob.year); printf("\nWho is %s's father? ", temp->name ); scanf("%s", temp->father ); printf("\nWho is %s's mother? ", temp -> name ); scanf("%s", temp -> mother ); temp->next = temp->previous = NULL; return temp; } 2. Analysis ----------- The topmost tree is [N]=AB AB[]AB. The first part AB is easy so we move on to AB[]AB. We will partition this into four parts: A B C D where A,B,C,D are parts of AB[]AB without some AB. This some AB we will call residual R. There are two main types of R: R outside A or B or C or D R inside A or B or C or D. Moving on to the analysis of A,B,C,D=AB[]AB-R: A=struct[] AB B=struct[] AB C=main[] F,W (I) D=struct[] AB. Which is better represented as AB[]AB-R=struct[]AB,main[] AB,(F,W) ,((I),) ,since A,B,D are of the same class. AB[]AB=A,B,C,D + R. And of course, the whole code is AB + AB[]AB. FOOTNOTE: --------- --------- A,B \ne AB A,B=A B; AB=a b A B=AB