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

Answer:

Easy. Just change the type given to the type variable. You also need to change the primitive ints to primitive doubles.


Linked List of Double

Notice that only the testing program needs to be changed. No change is needed for the GenericLinkedList class nor for the GenericNode class.

public class GenericLinkedListTester
{
  public static void main( String[] args )
  {
    // create an empty generic linked list
    GenericLinkedList<Double> list = new GenericLinkedList<>(); 
    
    // insert some doubles (autoboxed)
    // each literal must look like a double (include a decimal point)
    // for autoboxing to create a Double
    list.insertFirst( 4.0 );
    list.insertFirst( 3.3 );
    list.insertFirst( 2.2 );
    list.insertFirst( 1.0 );
   
    list.traverse();
    System.out.println("\n"); 
    
    // test getFirst()
    System.out.println("First: " + list.getFirst() );
    list.deleteFirst();
    list.traverse();
    System.out.println("\n"); 
    System.out.println("New First: " + list.getFirst() );
      
    // test getLast()
    System.out.println("Last : " + list.getLast() );
 
  }
}

QUESTION 11:

If you wanted a list of Bird objects, would any changes be needed to the GenericLinkedList class or the GenericNode class?


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