Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the function joinLinkedLists() to take in two nodes that represent the

ID: 3719937 • Letter: C

Question

Complete the function joinLinkedLists() to take in two nodes that represent the beginning of two Linked Lists, n1 and n2, and join these Linked Lists such that n2 is attached to the end of n1.

Example

n1: 100 -> 85 -> 75 -> 65

n2: 23 -> 22 -> 12 -> 10

joinLinkedLists(n1, n2)

# returns 100 -> 85 -> 75 -> 65 -> 23 -> 22 -> 12 -> 10

class Node:
def __init__(self, value):
self.value = value
self.next = None
  
def joinLinkedLists(n1, n2):
# TODO
  ?

class Node Problem 2 def _init__(self, value): self.value value self. next = None Complete the function joinLinkedLists() to take in two nodes that represent the beginning of two Linked Lists, n1 and n2, and join these Linked Lists such that n2 is attached to the end of nl. 4 6- def joinLinkedLists(n1, n2): Example nl: 100 -85 -75-> 65 n2: 23-22-12-10 # TOD0 #returns 100-> 85-> 75-> 65-> 23-> 22-> 12-> 10

Explanation / Answer

class Node: def __init__(self, value): self.value = value self.next = None def joinLinkedLists(n1, n2): temp = n1 while temp.next is not None: temp = temp.next temp.next = n2