1 for the GenericLinkedList
, 3 Bird
s, 3 GenericNode
s, 9 String
s
(3 per node) for a total of 16 objects.
The data structure is starting to get a little bit complicated.
get()
The get(int index)
method gets (copies) the value of a node at a particular index.
Here is the method for the unordered linked list of integers.
// get the value at index of the list // int get( int index ) throws IndexOutOfBoundsException { if ( isEmpty() ) throw new IndexOutOfBoundsException(); Node p = headPtr; int counter = 0; while ( counter<index && p != null ) { p = p.getNext(); counter++ ; } if ( index==counter ) return p.getValue(); else throw new IndexOutOfBoundsException(); }
What changes are necessary to include this method in the GenericLinkedList
class?