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:

Consider the following C program: #include "stdio.h" #include "stdlib.h" #include "string.h" typedef

#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 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 * ",mypt r->age); inorder (myptr->younger) int main)l int check-1; char temp_name [100] int temp_age; FAMILY ptr NULL printf("Creating family tree...In"); printf("*n") 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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!