Question: 4. Write a Java method merge to create a new doubly linked list N that contains elements alternately from two given doubly linked lists L

 4. Write a Java method merge to create a new doubly

4. Write a Java method merge to create a new doubly linked list N that contains elements alternately from two given doubly linked lists L and M. If you run out of elements in one of the lists, then append the remaining elements of the other list to N. Lists L and M should remain unchanged. The method should work for all lists, including empty lists. If any one of the two lists is empty, then the method should return a copy of the second list. For example, if list L contains 4 elements one, two, three, four, and list M contains 6 elements a, b, c, d, e", "1", then list N should contain the following elements: "one", "a", "two", "b", "three", "c" "four", "d", "e", "t". The method merge should have two parameters of type DList (references to lists L and M). It should return a reference of type DList) to the created list N. 5. The main method of DLinkTester class should test all your methods. Make sure to fully exercise the code of the methods (see p. 28 of the textbook). (Note: DList class has toString method that you can use to output list contents.)

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!