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.
Step by Step Answer:
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp