Question: This is in C not C++ Here is the given code. Please write the addRear, printLegal, and getAge functions #include #include #include typedef struct person

This is in C not C++
Here is the given code. Please write the addRear, printLegal, and getAge functions
#include#include #include typedef struct person { char *name; int age; struct person *next; } Person; void print(Person *); // prints the entire list Person *addFront(Person *, char *, int);// adds a new node to the front of the list Person *addRear(Person *, char *, int); // adds a new node to the end of the list void printLegal(Person *); // prints the names who are 21 or older int getAge(Person *, char *); // returns age of the name specified (or -1) int main(void) { char input1[100]; int input2; Person *myList = NULL; printf("Enter a person's name (one word) and age : "); scanf("%s %d", input1, &input2); while (input2 != 0) { if (input2 > 20) myList = addRear(myList, input1, input2); else myList = addFront(myList, input1, input2); printf("Enter a name (one word) and age, enter 'xxx' and 0 to exit : "); scanf("%s %d", input1, &input2); } printf(" "); print(myList); printf(" "); printLegal(myList); printf(" Enter the name of a person to look up their age : "); scanf("%s", input1); while ( strcmp(input1, "xxx") != 0 ) { printf("\t%s is %d years old ", input1, getAge(myList, input1) ); printf("Enter a name to look up their age or 'xxx' to exit : "); scanf("%s", input1); } return 0; } void print(Person *ptr) { printf("The list is : "); while (ptr) { printf("[%s-%d] ", ptr->name, ptr->age); ptr = ptr->next; } printf(" "); return; } Person *addFront(Person *ptr, char *n, int a) { Person *newNode = malloc( sizeof(Person) ); newNode->name = malloc( strlen(n) + 1 ); strcpy(newNode->name, n); newNode->age = a; newNode->next = ptr; return newNode; }
This lab maintains a linked list of people, where each node contains a name (one-word names only) and the age of that person. For example, a node might contain "BigA1" and 21The program operates as follows .Prompts the user for names and ages, building the list with calls to addFront and addRear Pnnts the entire list, and then pnnts only the people in the list who are 21 or older .Prompts the user for a name, and then prints the age of that person (if they are in the list) The code below is on Blackboard. Write the three functions addRear,printlegal and getAge. snclude
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
