Assignment #7: Linked List
Winter 1999
(To be completed for your lab period March 1-2)
Objective: To understand linked lists.
You are to write an interactive program that creates a linked list of data. The program should interact with the user so that the user can insert new items into the list, find a record in the list, and delete items from the list. You can ask the user for a string using the Stdin.getString() method.
Each element of the linked list will contain the following items:
1. a name (assume a single word, that is someone's last name),
2. the person's age,
3. the person's desired career occupation (a text description).
Your main program should create an empty list. It should then prompt the user for a command, which can be one of five things:
1. Insert - Create a new list element and put it into the list. Ask the user for the data to go in the list element.
2. Find - Ask the user for a name, and then find that name in the list and display the age and career.
3. Delete - Ask the user for a name, and then remove that person from the list.
4. List - Display the entire list.
5. Quit - Exit the program.
Make the program above maintain the list in sorted alphabetical order by the person's last name. Thus the insertion routine would have to insert any new item in the correct order.
Here is a sample interactive session:
Linked List Maintainer for Names, Ages and Careers Commands are I (insert), F (find), D (delete), L (list), Q (quit) Command? I name: Chretien age: 62 career: ballet dancer Inserted. Command? I name: Manning age: 63 career: Concert Pianist Inserted. Command? I name: Charest age: 39 career: Prime Minister Inserted. Command? F name: Manning Manning is 63 years old and wants to be a Concert Pianist Command? D name: Charest Charest deleted. Command? D name: Gump Gump is not in the linked list. Command? L Manning is 63 years old and wants to be a Concert Pianist Chretien is 62 years old and wants to be a ballet dancer Command? Q Goodbye