Question: Write a specialized singly linked list class in Python 3 . Our specialized list will have several unique properties: 1 . Our linked list stores

Write a specialized singly linked list class in Python3. Our specialized list will have several unique properties:
1. Our linked list stores only integers.
2. Elements in the linked list are kept in ascending order. This means the root stores the smallest element in the
list. The final element in the list is the largest.
3. It does not store duplicates. This means that attempting to insert an element that is already present will
result in no change to the list.
4. All tree operations must be implemented using iteration (not recursion)
OrderedLinkedListNode Class Requirements
This class is used by the list class below to store data and the next node.
class OrderedLinkedListNode:
The class must be called OrderedLinkedListNode.
def __init__(self, data):
The data parameter contains the integer data this node will store.
Should initialize a next_node variable to None. This member variable will store a reference to the next node
in the linked list.
def get_data(self):
Returns the contents of data member variable.
def get_next_node(self):
Return the contents of the next_node member variable.
def set_next_node(self, next_node):
Sets the next_node member variable to the next_node argument.
OrderedLinkedList Class Requirements
Pay close attention to section. Your class name and functions must conform exactly to the specifications given below.
When grading I will be using test code that expects the class and its member functions to have a specific format.
class OrderedLinkedList:
The class must be called OrderedLinkedList. It should utilize the OrderedLinkedListNode class above
def __init__(self):
Sets up all necessary variables.
The init function should build an empty list.
def get_root(self):
Returns the root node of the list, or None if the list is empty.
def insert(self, data):
Finds the location in the list where the value in data should be inserted.
If data is not in the list, it is inserted. After insertion, the list maintains its ascending sorted property.
If data is in the list, there is no change to the list.
If data was inserted into the list, insert returns True. If a duplicate was found, it should return False.
def remove(self, data):
Finds the location in the list where the value in data should be.
If data is in the list, it is removed. After removal, the list maintains its ascending sorted property.
If data is not in the list, there is no change to the list.
If data was removed from the list, remove returns True. If data was not in the list, the function returns False.
def contains(self, data):
Returns True or False depending on if data is in the list.
def print_list(self):
Prints the list on a single line with a terminating newline. For example: 169111820
def merge_list(self, other):
Merges the OrderedLinkedList, other, with this one. The resulting list should contain all the elements of this
list and the other list.
other should be unchanged.
Returns None

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!