Unformatted text preview:

1. Program 10 Instructions, CS102, Prof. LoftinWrite a class SortedLinkedList which handles a sorted linked list ofintegers. In particular, there should be the following public methods:SortedLinkedList() // constructor for empty listvoid add (int m) // add a node containing m into the listString toString()The add method should insert the new node in the correct place tokeep the list sorted.2. A sample driver class and outputHere is a sample driver class:public class Main{public static void main (String[] args){SortedLinkedList a = new SortedLinkedList();System.out.println(a);a.add(5);System.out.println(a);a.add(10);a.add(3);System.out.println(a);a.add(30);a.add(12);a.add(5);System.out.println(a);}}Here is the output of the driver class:[ ][ 5 ][ 3 5 10 ][ 3 5 5 10 12 30 ]3. How to do itModify the code for MyList.java that we discussed in class. Thething to change is the add method. Note that your code should cor-rectly add a node for a new integer in the following cases:• to an empty list• at the beginning of the list• in the middle of the list• at the end of the list12Be careful with your code. Make sure you avoid null pointer exceptions.4. Due date: December 7, 20095. How to turn it inSend your program SortedLinkedList.java as an email attachmentto


View Full Document

Rutgers University CS 102 - Program 10 Instructions

Download Program 10 Instructions
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Program 10 Instructions and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Program 10 Instructions 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?