Lect 08
Lect 08
x 22 v1 -385 22 42
v2 39
Searching a Vector
public int position (int item)
{ int k;
IntegerVector
data, numElements
add, get, set, position,
remove, length, toString
Uses of the IntegerVector
Class
• Solutions?
– Reallocate the data array (Exercise 4.9)
– Different implementation
Linked Lists
• Elegant solution to space problem
– Space is allocated as it is needed
– Each element has its own memory location
– These are linked together using references
(pointers)
s Bye
New Class: IntegerList
• Same public methods as IntegerVector
– Clients will see (almost) no difference
IntegerList
first, numElements
add, get, set, position,
remove, length, toString
Internal Details
public class IntegerList
{ private class ListNode
{ public int data; An Inner Class
public ListNode next;
} // class ListNode
numElements 4
ListNode
data -56 19 3 -2
next