Purchase Solution

Java Split Linked List Into Two Equal Sublists

Not what you're looking for?

Ask Custom Question

See the attachment.

Splitting a Linked List into two sublists of almost equal sizes

Add the method splitMid to the class LinkedListClass as follows:
Public void splitMid(LinkedListClass<T> sublist);
// This method splits the given list into two sublists of almost equal sizes
// Precondition: The list must exist
//Postcondition: first points to the first node, and last points to the last node of the first sublist
// sublist.first points to the first node, and sublist.last points to the
// last node of the second sublist.

Consider the following statements:
UnorderedLinkedList<Integer> myList;
UnorderedLinkedList<Integer> sublist;

Suppose myList points to the list with elements 34, 65, 27, 89, and 12 (in this order). The statement
myList.splitMid(subList);
splits myList into two sublists: myList points to the list with elements 34, 65, and 27. And subList points to the sublist with elements 89 and 12.
Write the definition of the method splitMid. Also write a program to test your method. (Use either the class UnorderedLinkedList or the class OrderedLinkedList to test your method).

Purchase this Solution

Solution Summary

The solution discusses the Java split linked list into two equal sublists.

Solution Preview

I have added the method splitMid() to the UnorderedArrayList.java. It is also declared in ...

Purchase this Solution


Free BrainMass Quizzes
Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

C# variables and classes

This quiz contains questions about C# classes and variables.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.