Challenges: Insert at Position and Merge Lists
Explore how to manage linked lists by implementing functions to insert nodes at any position and merge two separate lists into one. Understand the use of local references and pointer adjustments to manipulate list nodes efficiently without memory leaks.
The mergeLists function
Problem statement
The input consists of two lists. Write a function, mergeLists, which takes the two lists as inputs and concatenates them together. The list2 array should be appended to the end of list1.
The list2 array must be the empty list after the merge process.
For example:
list1 = [1, 2, 3]
list2 = [4, 5, 6]
After mergeLists:
list1 = [1, 2, 3, 4, 5, 6]
list2 = []
Challenge
Complete the function in the following code widget using local references. The definition of the list structure is present in the background.
Note: We stress again that it’s crucial to make a memory drawing to be able to ...