Question: class Node : def __init__ ( self , value) : self .value = value self . next = None def __str__ ( self ) :

class Node: def __init__(self, value): self.value = value self.next = None def __str__(self): return "Node({})".format(self.value) __repr__ = __str__ class SortedLinkedList: ''' >>> x=SortedLinkedList() >>> x.add(8.76) >>> x.add(1) >>> x.add(1) >>> x.add(1) >>> x.add(5) >>> x.add(3) >>> x.add(-7.5) >>> x.add(4) >>> x.add(9.78) >>> x.add(4) >>> x Head:Node(-7.5) Tail:Node(9.78) List:-7.5 -> 1 -> 1 -> 1 -> 3 -> 4 -> 4 -> 5 -> 8.76 -> 9.78 >>> x.replicate() Head:Node(-7.5) Tail:Node(9.78) List:-7.5 -> 1 -> 1 -> 1 -> 3 -> 3 -> 3 -> 4 -> 4 -> 4 -> 4 -> 4 -> 4 -> 4 -> 4 -> 5 -> 5 -> 5 -> 5 -> 5 -> 8.76 -> 9.78 >>> x Head:Node(-7.5) Tail:Node(9.78) List:-7.5 -> 1 -> 1 -> 1 -> 3 -> 4 -> 4 -> 5 -> 8.76 -> 9.78 >>> x.removeDuplicates() >>> x Head:Node(-7.5) Tail:Node(9.78) List:-7.5 -> 1 -> 3 -> 4 -> 5 -> 8.76 -> 9.78 ''' def __init__(self): # You are not allowed to modify the constructor self.head=None self.tail=None def __str__(self): # You are not allowed to modify this method 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 isEmpty(self): return self.head == None def __len__(self): count=0 current=self.head while current: current=current.next count+=1 return countdef replicate(self): # --- YOUR CODE STARTS HERE passdef removeDuplicates(self): # --- YOUR CODE STARTS HERE pass

question:

class Node: def __init__(self, value): self.value = value self.next = None def__str__(self): return "Node({})".format(self.value) __repr__ = __str__ class SortedLinkedList: ''' >>> x=SortedLinkedList() >>>

replicate(sel (2.5 points) Returns a new SortedLinkedList object where each element of the linked list appears its node's value number of times (3 > 1 results in 3 > 3 -> 3 -> 1). Negative numbers and oats are ignored, they are not repeated but should be included in the list. For 0, the node is added in the new list only once. Method returns None if the list is empty. Hint: Using the add method from above could be very useful here! Oulput SortedLinkedList A new linked list object that repeats positive integer values value times. It does not modify the original list N None keyword is returned if the original list is empty removeDuplicates(self) (2.5 points) Removes any duplicate nodes from the list, so it modifies the original list. This method must traverse the list only once. It modifies the original list. Output None Nothing is returned when the method completes the work

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!