Please help, and please use the functions provided (in python) – Refer to questions attached in the images, and the starter code below (I cannot upload page 3 with example outputs for removeDuplicates(self)). Do not change the function names or given starter code in your script. You are not allowed to use any other data structures for the purposes of manipulating/sorting elements, nor may you use any modules from the Python to insert and remove elements from the list. You  are  not  allowed  to  swap  data  from  the  nodes  when  adding  the  node  to  be  sorted. Traversing  the  linked  list  and  updating  ‘next’  references  are  the  only  required  and acceptable operations. You are not allowed to use any kind of built-in sorting method or import any other libraries. If you are unable to complete a function, use the pass statement to avoid syntax errors.   Starter code -  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 -> -7.5 -> 1 -> 1 -> 1 -> 3 -> 3 -> 3 -> 4 -> 4 -> 4 -> 4 -> 4 -> 4 -> 4 -> 4 -> 5 -> 5 -> 5 -> 5 -> 5 -> 8.76 -> 8.76 -> 9.78 -> 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 f'Head:{self.head}\nTail:{self.tail}\nList:{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 count def add(self, value): # --- YOUR CODE STARTS HERE pass def replicate(self): # --- YOUR CODE STARTS HERE pass def removeDuplicates(self): # --- YOUR CODE STARTS HERE pass               -page 3 continued-   removeDuplicates(self)                                                                                                     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   Examples: >>> x=SortedLinkedList() >>> x.removeDuplicates() >>> x Head:None Tail:None List: >>> x.add(1) >>> x.add(1) >>> x.add(1) >>> x.add(1) >>> x Head:Node(1) Tail:Node(1) List:1 -> 1 -> 1 -> 1 >>> x.removeDuplicates() >>> x Head:Node(1) Tail:Node(1) List:1 >>> x.add(1) >>> x.add(2) >>> x.add(2) >>> x.add(2) >>> x.add(3) >>> x.add(4) >>> x.add(5) >>> x.add(5) >>> x.add(6.7) >>> x.add(6.7) >>> x Head:Node(1) Tail:Node(6.7) List:1 -> 1 -> 2 -> 2 -> 2 -> 3 -> 4 -> 5 -> 5 -> 6.7 -> 6.7 >>> x.removeDuplicates() >>> x Head:Node(1) Tail:Node(6.7) List:1 -> 2 -> 3 -> 4 -> 5 -> 6.7

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please help, and please use the functions provided (in python) – Refer to questions attached in the images, and the starter code below (I cannot upload page 3 with example outputs for removeDuplicates(self)). Do not change the function names or given starter code in your script. You are not allowed to use any other data structures for the purposes of manipulating/sorting elements, nor may you use any modules from the Python to insert and remove elements from the list. You  are  not  allowed  to  swap  data  from  the  nodes  when  adding  the  node  to  be  sorted. Traversing  the  linked  list  and  updating  ‘next’  references  are  the  only  required  and acceptable operations. You are not allowed to use any kind of built-in sorting method or import any other libraries. If you are unable to complete a function, use the pass statement to avoid syntax errors.

 

Starter code - 

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 -> -7.5 -> 1 -> 1 -> 1 -> 3 -> 3 -> 3 -> 4 -> 4 -> 4 -> 4 -> 4 ->
4 -> 4 -> 4 -> 5 -> 5 -> 5 -> 5 -> 5 -> 8.76 -> 8.76 -> 9.78 -> 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 f'Head:{self.head}\nTail:{self.tail}\nList:{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 count

def add(self, value):
# --- YOUR CODE STARTS HERE
pass
def replicate(self):
# --- YOUR CODE STARTS HERE
pass
def removeDuplicates(self):
# --- YOUR CODE STARTS HERE
pass
 
 
 
 
 
 
 
-page 3 continued-
 
removeDuplicates(self)                                                                                                    
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
 
Examples:
>>> x=SortedLinkedList()
>>> x.removeDuplicates()
>>> x
Head:None
Tail:None
List:
>>> x.add(1)
>>> x.add(1)
>>> x.add(1)
>>> x.add(1)
>>> x
Head:Node(1)
Tail:Node(1)
List:1 -> 1 -> 1 -> 1
>>> x.removeDuplicates()
>>> x
Head:Node(1)
Tail:Node(1)
List:1
>>> x.add(1)
>>> x.add(2)
>>> x.add(2)
>>> x.add(2)
>>> x.add(3)
>>> x.add(4)
>>> x.add(5)
>>> x.add(5)
>>> x.add(6.7)
>>> x.add(6.7)
>>> x
Head:Node(1)
Tail:Node(6.7)
List:1 -> 1 -> 2 -> 2 -> 2 -> 3 -> 4 -> 5 -> 5 -> 6.7 -> 6.7
>>> x.removeDuplicates()
>>> x
Head:Node(1)
Tail:Node(6.7)
List:1 -> 2 -> 3 -> 4 -> 5 -> 6.7
 

 
Section 1: The Sorted Linked List class
add(self, 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 but modifies the linked list. The items in the list might not be
unique, but you can assume every value will be numerical (int and float). You are not allowed to
traverse the linked list more than once (only one loop required).
Input (excluding self)
int or float
item A numerical value that represents the value of a Node object
Examples:
>>> x=SortedLinked List()
>>> x. add (8.76)
>>> x. add(7)
>>> x. add (3)
>>> x. add(-6)
>>> x. add (58)
>>> x. add (33)
>>> x. add (1)
>>> x. add(-88)
>>> print(x)
Head : Node( -88)
Tail:Node(58)
List:-88 -> -6 -> 1 -> 3 -> 7 -> 8.76 -> 33 -> 58
replicate(self)
Returns a new SortedLinkedList object where each elemet of the linked list appears its
node's value number of times (3 -> 1 results in 3 -> 3 -> 3 -> 1). Negative numbers and floats are
repeated only once immediately after that node. For 0, the node is added, but not repeated.
Method returns None if the list is empty. Hint: Using the add method from above could be very
useful here!
Output
SortedLinkedList A new linked list object that repeats values without disturbing the original
list
None
None keyword is returned if the original list is empty
Transcribed Image Text:Section 1: The Sorted Linked List class add(self, 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 but modifies the linked list. The items in the list might not be unique, but you can assume every value will be numerical (int and float). You are not allowed to traverse the linked list more than once (only one loop required). Input (excluding self) int or float item A numerical value that represents the value of a Node object Examples: >>> x=SortedLinked List() >>> x. add (8.76) >>> x. add(7) >>> x. add (3) >>> x. add(-6) >>> x. add (58) >>> x. add (33) >>> x. add (1) >>> x. add(-88) >>> print(x) Head : Node( -88) Tail:Node(58) List:-88 -> -6 -> 1 -> 3 -> 7 -> 8.76 -> 33 -> 58 replicate(self) Returns a new SortedLinkedList object where each elemet of the linked list appears its node's value number of times (3 -> 1 results in 3 -> 3 -> 3 -> 1). Negative numbers and floats are repeated only once immediately after that node. For 0, the node is added, but not repeated. Method returns None if the list is empty. Hint: Using the add method from above could be very useful here! Output SortedLinkedList A new linked list object that repeats values without disturbing the original list None None keyword is returned if the original list is empty
Section 1: The SortedLinked List class
Examples:
>>> x=SortedLinkedList()
>>> x. add(4)
>>> x. replicate()
He ad: Node (4)
Tail:Node (4)
List:4 -> 4 -> 4 - > 4
>>> x. add(-23)
>>> x. add(2)
>>> x. add(1)
>>> x. add(20.8)
>>> X
He ad: Node (-23)
Tail:Node (20.8)
List:-23 -> 1 -> 2 -> 4 -> 20.8
>>> x. replicate()
He ad : Node (-23)
Tail:Node (20.8)
List:-23 -> -23 -> 1 -> 2 -> 2 -> 4 -> 4 -> 4 -> 4 -> 20.8 -> 20.8
>>> x. add(-1)
>>> x. add(0)
>>> x. add(3)
>>> x. replicate()
Head: Node (-23)
Tail:Node ( 20.8)
List:-23 -> - 23 -> -1 -> -1 -> 0 -> 1 -> 2 -> 2 -> 3 -> 3 -> 3 -> 4 -> 4 -> 4 -> 4 ->
20.8 -> 20.8
>>> X
Head: Node (-23)
Tail:Node (20.8)
List:-23 - > -1 -> 0 -> 1 -> 2 -> 3 -> 4 -> 20.8
>>> x.add(2)
>>> x.replicate()
He ad: Node (-23)
Tail:Node ( 20.8)
List:-23 -> - 23 -> -1 -> -1 -> 0 -> 1 - > 2 -> 2 - > 2 -> 2 -> 3 -> 3 -> 3 -> 4 -> 4 -> 4
-> 4 -> 20.8 -> 20.8
removeDuplicates(self)
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
Transcribed Image Text:Section 1: The SortedLinked List class Examples: >>> x=SortedLinkedList() >>> x. add(4) >>> x. replicate() He ad: Node (4) Tail:Node (4) List:4 -> 4 -> 4 - > 4 >>> x. add(-23) >>> x. add(2) >>> x. add(1) >>> x. add(20.8) >>> X He ad: Node (-23) Tail:Node (20.8) List:-23 -> 1 -> 2 -> 4 -> 20.8 >>> x. replicate() He ad : Node (-23) Tail:Node (20.8) List:-23 -> -23 -> 1 -> 2 -> 2 -> 4 -> 4 -> 4 -> 4 -> 20.8 -> 20.8 >>> x. add(-1) >>> x. add(0) >>> x. add(3) >>> x. replicate() Head: Node (-23) Tail:Node ( 20.8) List:-23 -> - 23 -> -1 -> -1 -> 0 -> 1 -> 2 -> 2 -> 3 -> 3 -> 3 -> 4 -> 4 -> 4 -> 4 -> 20.8 -> 20.8 >>> X Head: Node (-23) Tail:Node (20.8) List:-23 - > -1 -> 0 -> 1 -> 2 -> 3 -> 4 -> 20.8 >>> x.add(2) >>> x.replicate() He ad: Node (-23) Tail:Node ( 20.8) List:-23 -> - 23 -> -1 -> -1 -> 0 -> 1 - > 2 -> 2 - > 2 -> 2 -> 3 -> 3 -> 3 -> 4 -> 4 -> 4 -> 4 -> 20.8 -> 20.8 removeDuplicates(self) 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
Expert Solution
Step 1

Find an implementation below.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY