Question: Consider the following C program: #include stdio.h #include stdlib.h #include string.h typedef struct family{ char *name; int age; struct family *younger; struct family *older; }
Consider the following C program:

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
typedef struct family{
char *name;
int age;
struct family *younger;
struct family *older;
} FAMILY;
void insert_node (FAMILY **myptr, char *temp_name, int temp_age);
void inorder(FAMILY *myptr) {
if (myptr !=NULL) {
inorder(myptr->older);
printf(" * %s - %d * ",myptr->name,myptr->age);
//printf(" * %d * ",myptr->age);
inorder(myptr->younger);
}
}
int main() {
int check=1;
char temp_name[100];
int temp_age;
FAMILY *ptr=NULL;
printf("Creating family tree... ");
printf("*********************** ");
while (check) {
printf("Please insert name: ");
scanf("%s",temp_name);
printf("Please insert age: ");
scanf("%d", &temp_age);
insert_node(&ptr, temp_name, temp_age);
printf("Any more family members? Y/N(1/0): ");
scanf("%d",&check);
}
inorder(ptr);
return 0;
}
Write the insert_node function such that the first member of the family will be the root node and all subsequent members will be inserted into the tree following their ages, whereby the younger members will be pointed to by struct family *younger and the older members will be pointed to by struct family *older.
#include #include #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
