Question: class Node: def __init__(self, value): self.value = value self.next = None def __str__(self): return Node({}).format(self.value) __repr__ = __str__ class OrderedLinkedList: ''' Creates a linked list

 class Node: def __init__(self, value): self.value = value self.next = None
def __str__(self): return "Node({})".format(self.value) __repr__ = __str__ class OrderedLinkedList: ''' Creates a
class Node:
def __init__(self, value):
self.value = value
self.next = None
def __str__(self):
return "Node({})".format(self.value)
__repr__ = __str__
class OrderedLinkedList:
'''
Creates a linked list in ascending order
>>> x=OrderedLinkedList()
>>> x.pop()
'List is empty'
>>> x.add(8)
>>> x.add(7)
>>> x.add(3)
>>> x.add(-6)
>>> print(x)
Head:Node(-6)
Tail:Node(8)
List:-6 3 7 8
>>> len(x)
4
>>> x.pop()
8
>>> print(x)
Head:Node(-6)
Tail:Node(7)
List:-6 3 7
'''
def __init__(self):
self.head=None
self.tail=None
def __str__(self):
temp=self.head
out=[]
while temp:
out.append(str(temp.value))
temp=temp.next
out=' '.join(out)
return ('Head:{} Tail:{} List:{}'.format(self.head,self.tail,out))
__repr__=__str__
def add(self, value):
#write your code here
def pop(self):
#write your code here
def isEmpty(self):
#write your code here
def __len__(self):
#write your code here

In class, we have been working on the implementation of a singly linked list. That data structure keeps the elements of the linked list unsorted. Based on the LinkedList code, implement the data structure OrderedLinkedList with the following characteristics: Ordered inkedListO creates a new ordered list that is empty. It needs no parameters and returns nothing. You can assume the items in the list are unique .add(item) adds a new Node with value-item to the list making sure that the ascending order is preserved. It needs the item and returns nothing. pop) removes and returns the last Node in the list. It needs nothing and returns the value . of the Node isEmpt0 tests to see whether the list is empty. It needs no parameters and returns a boolean len(list object) returns the number of items in the list. It needs no parameters and returns an integer NOTE: To grade this assignment, the grading script will perform a series of mixed linked list operations and compare the final status of your list. Verify that all your methods work correctly when mixed together. EXAMPLE >>> x-OrderedLinkedList >>x.isEmpty) True >>>x.pop List is empty >> x.add (7) x x.add(-6) >>> x.add (58) >x.add 133) >>x.add (3) print(x) Head:Node (-88) Labe (2) LADT LADS Dy MacBook Air 5 6 7 8

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 Databases Questions!