Source of 21.12.java


  1: // @author Frank M. Carrano, Timothy M. Henry
  2: // @version 5.0

  4: // Returns the index of either the entry that contains key or
  5: // the location that should contain key, if no such entry exists.
  6: private int locateIndex(K key)
  7: {
  8:    // Search until you either find an entry containing key or
  9:    // pass the point where it should be
 10:    int index = 0;
 11:    while ( (index < numberOfEntries) &&
 12:            key.compareTo(dictionary[index].getKey()) > 0 )
 13:    {
 14:       index++;
 15:    } // end while

 17:    return index;
 18: } // end locateIndex

 20: // Makes room for a new entry at a given index by shifting
 21: // array entries towards the end of the array.
 22: private void makeRoom(int keyIndex)
 23: {
 24:    // Exercise!
 25: } // end makeRoom