Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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 oneHeadStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started