2 * insert-sort vector (default to strings)
8 public class SortedVector {
12 public SortedVector() {
13 theList = new Vector();
17 public SortedVector( sorter s ) {
18 theList = new Vector();
22 public int addElement( Object theId ) {
24 for( i = 0; i < theList.size(); i++ ) {
26 cmp = cmpr.cmp( theList.elementAt( i ), theId );
28 if( cmp == 0 ) return -1;
33 theList.insertElementAt( theId, i );
37 public Object firstElement() {
38 return theList.firstElement();
41 public Object removeItem( int index ) {
42 if( (index < 0) || (index > theList.size()) )
45 Object theItem = theList.elementAt( index );
46 theList.removeElementAt( index );
50 public int removeElement( Object theItem ) {
51 for( int i = 0; i < theList.size(); i++ ) {
53 equal = cmpr.cmp( theList.elementAt( i ), theItem ) == 0;
55 theList.removeElementAt( i );
62 public boolean isElement( Object theItem ) {
63 for( int i = 0; i < theList.size(); i++ ) {
64 if( cmpr.cmp( theList.elementAt( i ), theItem ) == 0 )
70 public void removeAllElements() {
71 theList.removeAllElements();
74 public Enumeration elements() {
75 return theList.elements();
79 return theList.size();