Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Part B: Implement a Sorted Doubly Linked list ( 1 0 marks ) The class declarations have been created in the a 1 _ partb.py
Part B: Implement a Sorted Doubly Linked list marks
The class declarations have been created in the apartb.py starter file. You are responsible to write all the listed functions.
You are allowed to add data members and helper functions to both Node and DoublyLInked classes.
You are not allowed to removechange the interfaces of the listed functions
Only the listed functions will be called directly by the tester, thus any helper functions you add must be called from those listed below
Node
The Node class is declared within SortedList. It stores:
a piece of data
a reference to the next Node in the SortedList None if Node is last node
a reference to the previous Node in the SortedList None if Node is first node
When a Node is initialized, it is passed a data value. Optionally it is also passed a reference to the next node and a reference to the previous node in that order If the data values are not passed in they are defaulted to None.
The Node function has the following member functions:
def getdataself
function returns data stored in node
def getnextself
function returns reference to next node in SortedList
def getpreviousself
function returns reference to previous node in SortedList
SortedList
A SortedList is a sorted doubly linked list.
A sorted linked list is a linked list where values stay sorted from smallest to biggest with the smallest node at the front of the list and the largest node at the back.
When the SortedList is first created it is empty.
The SortedList has the following member functions
def getfrontself
This function returns a reference to the first data node in the list. If list is empty, function returns None
def getbackself
This function returns a reference to the last data node in the list. If list is empty, function returns None
def isemptyself
This function returns True if the list is empty, False otherwise
def lenself
This function returns the number of values stored in the list
def insertselfdata
this function inserts data into the list such that the list stays sorted. You may assume that the data being added can be compared using comparison operators. Function returns reference to newly added node.
def eraseself node
This function removes the node referred to by the node argument. This function returns nothing. If node is None, function does not alter list and will raise the ValueError with this statement:
raise ValueErrorCannot erase node referred to by None'
def searchself data
This function returns a reference to the node containing data if it exists within the list, None if no node contains data
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started