home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / bbxxk / iaseq.c__ / IASEQ.C
Encoding:
Text File  |  1992-10-26  |  990 b   |  33 lines

  1. /* Copyright (c) IBM Corp. 1992 */
  2.  
  3.  
  4. template < class Element >
  5. long IASequence < Element >::
  6. compare (IASequence < Element > const& collection,
  7.          long (*comparisonFunction) (Element const&, Element const&)) const
  8. { long result = 0;
  9.   ICursor *thisCursor = newCursor ();
  10.   ICursor *collectionCursor = collection.newCursor ();
  11.  
  12.   for (thisCursor->setToFirst (), collectionCursor->setToFirst ();
  13.        result == 0 && thisCursor->isValid () && collectionCursor->isValid ();
  14.        thisCursor->setToNext (), collectionCursor->setToNext ()) {
  15.     result = (*comparisonFunction) (this->elementAt (*thisCursor),
  16.                       collection.elementAt (*collectionCursor));
  17.   }
  18.  
  19.   if (result == 0) {
  20.     if (thisCursor->isValid () && ! collectionCursor->isValid ())
  21.       result = 1;
  22.     else if (! thisCursor->isValid () && collectionCursor->isValid ())
  23.       result = -1;
  24.     else {
  25.     }
  26.   }
  27.   delete thisCursor;
  28.   delete collectionCursor;
  29.  
  30.   return result;
  31. }
  32.  
  33.