Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (anonymous):

Having issues with this java problem. Describe an algorithm for concatenating two singly linked lists L and M, into a single list L' that contains all the nodes of L followed by all the nodes of M. But, rather than just describe such an algorithm, create a Java program and method(s) that will do so. Consider using at least three lists. Two of them L and M (although create better names – and lowercase like ‘first’ and ‘second’) you will create and populate with GameEntry objects. The third list L’ (or ‘concat’) will contain the concatenated nodes. Create a method named concatenate () that looks

OpenStudy (anonymous):

like this: public static SinglyLinkedList concatenate (SinglyLinkedListfirst, SinglyLinkedListsecond); Print the first two lists before calling concatenate. Then print the concatenated list. (And, SinglyLinkedList does contain a ‘toString’ method that can be used.) Use class SinglyLinkedList of the net.datastructures package.

OpenStudy (anonymous):

here is the package and documentation for SinglyLinkedList http://cs.slu.edu/~goldwasser/dsaj/docs/

OpenStudy (anonymous):

It's quite simple. You take the last node of L and have it point at the first node of M.

OpenStudy (anonymous):

However, depending on your use case, you might want to copy the lists first.

OpenStudy (anonymous):

That interface doesn't seem to have a means to iterate through the list. It doesn't make much sense.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!