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 Python Our specialized list will have several unique properties:
Our linked list stores only integers.
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.
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.
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 initself data:
The data parameter contains the integer data this node will store.
Should initialize a nextnode variable to None. This member variable will store a reference to the next node
in the linked list.
def getdataself:
Returns the contents of data member variable.
def getnextnodeself:
Return the contents of the nextnode member variable.
def setnextnodeself nextnode:
Sets the nextnode member variable to the nextnode 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 initself:
Sets up all necessary variables.
The init function should build an empty list.
def getrootself:
Returns the root node of the list, or None if the list is empty.
def insertself 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 removeself 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 containsself data:
Returns True or False depending on if data is in the list.
def printlistself:
Prints the list on a single line with a terminating newline. For example:
def mergelistself 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
