Question
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,
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 BigAl and 21. The program operates as follows
Prompts the user for names and ages, building the list with calls to add, printing the list after each add
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. You must do the following:
Write the function getAge that returns the age of the name passed to it, or -1 if the person does not exist
Re-write add so that it adds in alphabetical order. Do not add a name if it already exists in the list. That is, before adding, traverse the list to make sure the name is not already there. Print an error message if it exists.
Two sample inputs for the program are shown at the bottom right of the code
#includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started