Write a method called transferFrom that accepts a second linked list as a parameter and that moves

Question:

Write a method called transferFrom that accepts a second linked list as a parameter and that moves values from the second list to this list. You are to attach the second list’s elements to the end of this list. You are also to empty the second list. For example, suppose two lists called list1 and list2 store [8, 17, 2, 4] and [1, 2, 3], respectively. The call of list1.transferFrom(list2); should change list1 to [8, 17, 2, 4, 1, 2, 3] and list2 to an empty list, []. The order of the arguments matters; list2.transferFrom(list1); should change list1 to an empty list, [], and list2 to [1, 2, 3, 8, 17, 2, 4]. Either of the two lists could be empty, but you can assume that neither list is null. You are not to create any new nodes. Your method should simply change links of the lists to join them together.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: