Python For this assignment, you will write a program to allow the user to store the names and phone numbers of their contacts. Create the following classes: Contact: two attributes. One for the contact's name and the contact's phone number. Node: two attributes: _data and _next. For use in a linked list. ContactList: One attribute: _head, a reference to the head of an internal linked list of Node objects. Note: self._head is an attribute of the class, so any method which updates the internal linked list can simply update the list self._head references. There is no need to return anything like we did in methods such as add_to_end in the lecture. Note also that for the same reason, we do not have to pass a reference to the head of the list to any method, because each method should already have access to the self._head attribute. ContactList should also have the following methods: add(name, new_number). Creates a new Node with a Contact object as its _data. The new Node is then added to ContactList's internal linked list referenced by _first_node. This will be a little different from what we've seen so far, because the Contacts should remain sorted in alphabetical order. When a Node is added to the linked list, find its correct location based on the Contact it holds and place the Node there. Do not worry about sorting by last name, just by overall name i.e., "Ryan Adams" should go after "Jill Smith". String objects in Python can be tested for alphabetical ordering with the > and < operators. Override __str__ so that it returns a nicely formatted string with each Contact's name and phone number. remove(name). Remove the Contact with the given name from the list, if it exists. change_phone_number(name, new_number). Update the phone number of the contact with the given name, if it exists. On main.py, create a ContactList object and then write a menu-based while loop that gives the user five options: add, remove, change phone number, print contacts, and quit. Make sure to test as many corner cases as possible (i.e., does it work when you remove the first Contact? How about the last Contact? etc.) Note: You are not required to perform a sort on the list! When you add a new Contact, the method only needs to find the correct location for that particular object. For example, if the user adds 'Bob' to an empty ContactList, it becomes the first (and only) Contact. If the user then adds 'Adam', it becomes the new head of the list (since it comes before 'Bob' alphabetically). Finally, if the user adds Barb, the list should be Adam ->Barb ->Bob. Hint: each call to 'add' only adds a single Contact to a list which is already in sorted order.
Types of Linked List
A sequence of data elements connected through links is called a linked list (LL). The elements of a linked list are nodes containing data and a reference to the next node in the list. In a linked list, the elements are stored in a non-contiguous manner and the linear order in maintained by means of a pointer associated with each node in the list which is used to point to the subsequent node in the list.
Linked List
When a set of items is organized sequentially, it is termed as list. Linked list is a list whose order is given by links from one item to the next. It contains a link to the structure containing the next item so we can say that it is a completely different way to represent a list. In linked list, each structure of the list is known as node and it consists of two fields (one for containing the item and other one is for containing the next item address).

Trending now
This is a popular solution!
Step by step
Solved in 6 steps with 4 images









