Source of 17.24.java


  1: // @author Frank M. Carrano, Timothy M. Henry
  2: // @version 5.0
  3: public int getPosition(T anEntry)
  4: {
  5:    int position = 1;
  6:    int length = list.getLength();

  8:    // Find position of anEntry
  9:    while ( (position <= length) &&
 10:            (anEntry.compareTo(list.getEntry(position)) > 0) )
 11:    {
 12:       position++;
 13:    } // end while

 15:    // See whether anEntry is in list
 16:    if ( (position > length) ||
 17:         (anEntry.compareTo(list.getEntry(position)) != 0) )
 18:    {
 19:       position = -position; // anEntry is not in list
 20:    } // end if

 22:    return position;
 23: } // end getPosition