go to previous page   go to home page   go to next page

Answer:

Maybe. Might be nice to test it.


Testing Program

This testing program asks how many nodes the user wants, then creates a linked list of random integers in the range 0 to 1000. To run it, put it in a file OrderedLinkedListTester.java in the same directory (or BlueJ project) as Node.java and OrderedLinkedList.java.

import java.util.* ;

public class OrderedLinkedListTester
{
  public static void main( String[] args )
  {
    OrderedLinkedList list = new OrderedLinkedList();
    Scanner scan = new Scanner( System.in );
    Random rand = new Random();
    
    System.out.print("How many nodes? ");
    int numNodes = scan.nextInt();
    for ( int j = 0; j<numNodes; j++ )
    {
      list.insertInOrder( rand.nextInt(1001) );
    }

  }
}

A better testing program would carefully test each case. Randomly generated data might miss some cases.

Try out the program with 10,000 values, or more, and see if the linked list can handle it.


QUESTION 13:

How could you delete the entire LinkedList ?


go to previous page   go to home page   go to next page