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

Answer:

A good test would be to generate random integers, insert them into the list, then print out the list to see if it is in order.


Testing Program

Here is a testing program:

// OLLTesterRandom.java
//
import java.util.* ;

public class OLLTesterRandom
{
  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) );
    }
    list.traverse();  
  }
} 

Here is a test run:

PS C:\JavaSource> javac OLLTesterRandom.java OrderedLinkedList.java Node.java
PS C:\JavaSource> java OLLTesterRandom
How many nodes? 20
38, 52, 79, 212, 236, 239, 261, 262, 330, 393, 615, 716, 729, 730, 761, 796, 819, 857, 860, 931
PS C:\JavaSource>

This code works as expected, but there is a serious problem. What is it?


QUESTION 10:

Say a linked list has grown to be 10,000 nodes long. (This could easily happen in a realistic situation.) How often will a new node be inserted at the end?


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