Question: Need to write a Java method that zips two linked lists together alternately, like in the picture. Currently have this written for code: This does

 Need to write a Java method that zips two linked lists

Need to write a Java method that zips two linked lists together alternately, like in the picture.

Currently have this written for code:

together alternately, like in the picture. Currently have this written for code:

This does not seem to be working when there are lists that are different sizes though. Say that l1 has {1, 3} and l2 has {2, 4, 6, 8} I am not merging all of these values into the final output list correctly. Any help or pointers in the right direction would be awesome.

public static Node zipDestructive(Node 11, Node 12) { if(11 == null) return 12; if(12 == null) return 11; Node oneHead = 11, p = 11, q = 12, lag = p, lag2 = 9; while(p != null && != null) { p = p.next; q = 9.next; lag.next = lag2; lag2.next = p; lag = p; lag2 = 9; return oneHead

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!