Assignment: Chapter 18 introduces you to linked lists. In this assignment, you will adapt the algorithms presented in this chapter to implement a phone book (a list of names and respective phone numbers kept in alphabetical order). Detailed specifications:
Define a structure to hold the contact's information including: name, phone number, and a pointer to the next node on the list. Each node on the list will be a contact instead of a number (like the example in the book).
struct ContactNode {
string name;
string phoneNumber;
ContactNode *next;
}
Define a class containing the structure, private member variable head (that will point to the beginning of the list), and the following member functions:
- A constructor that will initialize the head.
- A destructor that will destroy the list. This method needs to delete one node at a time.
- A method to add contacts to the list. This method must insert a node at the right place in order to keep the list sorted.
- A method to traverse the list to print all contacts.
You can find an implementation for those operations in the book and slides. Your main program should instantiate an object of the Names List and ask the user to enter a list of names (first and last), which you will insert in alphabetical order by calling the appropriate method. When the user is done entering the names, call the displayList method to display the names, which should be in alphabetical order.