Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

Currently have this written for code:

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Draft a proposal for a risk assessment exercise.

Answered: 1 week ago