Main Page | Compound List | File List | Compound Members

TreeTest.OrderedVector Class Reference

List of all members.

Detailed Description

An ordered version of the Vector object.


Public Member Functions

 OrderedVector ()
boolean add (Object obj)
 Override the Vector add(Object) method.


Constructor & Destructor Documentation

TreeTest.OrderedVector.OrderedVector  ) 
 

00018         {
00019             super();
00020         }


Member Function Documentation

boolean TreeTest.OrderedVector.add Object  obj  ) 
 

Override the Vector add(Object) method.

The method implements and ordered insert. All elements in the ordered vector are unique (so if the Integer is found in the Vector it will not be added).

This algorithm has an N2 worst case time complexity so it is not designed for efficiency.

00035         {
00036             Integer newInt = (Integer)obj;
00037             int len = size();
00038             boolean found = false;
00039             int i;
00040             for (i = 0; i < len; i++) {
00041                 Integer intObj = (Integer)elementAt( i );
00042                 if (newInt.compareTo( intObj ) > 0) {
00043                     continue;
00044                 }
00045                 else {
00046                     if (newInt.compareTo( intObj ) == 0) {
00047                         found = true;
00048                     }
00049                     break;
00050                 }
00051             } // for
00052             if (i == len) {
00053                 addElement( newInt );
00054             }
00055             else if (!found) {
00056                 insertElementAt( newInt, i );
00057             }
00058             return true;
00059         } // add


The documentation for this class was generated from the following file:
Generated on Mon Sep 1 20:49:25 2003 for BinaryTree by doxygen 1.3.3