Question: PYTHON: Hi, I am trying to create a function that would grab two Linked Lists and merge and sort them together. That same function would

PYTHON: Hi, I am trying to create a function that would grab two Linked Lists and merge and sort them together. That same function would also delete the elements of one of the merged Linked Lists.

For example: LinkedListA = 1 -> 3 -> 5 -> 7 ->9 LinkedListB = 2 -> 4 -> 6 -> 8 ->10

The new merged list would be: LinkedListA: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 ->10

And the LinkedListB would become "Null/None"> LinkedListB: Null

CODE:

PYTHON: Hi, I am trying to create a function that would grab Thanks!

1 2. 3 class LinkedList(object): definit__(self): self.head = None self.next = None 4 5 A 6 7 # Linked List Node: 8 9 10 class Node (object): def _init__(self, d): self.data = d self.next = None 11 12 13 14 15 o 16 # Function to insert a value at the head of the Linked List: def Head(self, value): newNode self.Node(value) newNode.next = self.head self.head = newNode 17 18 A 19 20 # Function to merge the Linked Lists: 21 22 23 24 25 # Function to print Linked List: def Print(self): temp = self.head while temp is not None: print(str(temp.data)) temp temp.next print(""). 26 27 A 28 A 29 30 31

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!