home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IAKSBAG.C < prev    next >
Text File  |  1993-09-22  |  2KB  |  42 lines

  1. /*******************************************************************************
  2. *                                                                              *
  3. * COPYRIGHT:                                                                   *
  4. *   IBM C/C++ Tools Version 2.01 - Collection Class Library                    *
  5. *   Licensed Materials - Property of IBM                                       *
  6. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  7. *   All Rights Reserved                                                        *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  10. *                                                                              *
  11. *******************************************************************************/
  12.  
  13. template < class Element, class Key >
  14. long IAKeySortedBag < Element, Key >::
  15. compare (IAKeySortedBag < Element, Key > const& collection,
  16.          long (*comparisonFunction) (Element const&, Element const&)) const
  17. { long result = 0;
  18.   ICursor *thisCursor = newCursor ();
  19.   ICursor *collectionCursor = collection.newCursor ();
  20.  
  21.   for (thisCursor->setToFirst (), collectionCursor->setToFirst ();
  22.        result == 0 && thisCursor->isValid () && collectionCursor->isValid ();
  23.        thisCursor->setToNext (), collectionCursor->setToNext ()) {
  24.     result = (*comparisonFunction) (this->elementAt (*thisCursor),
  25.                                       collection.elementAt (*collectionCursor));
  26.   }
  27.  
  28.   if (result == 0) {
  29.     if (thisCursor->isValid () && ! collectionCursor->isValid ())
  30.       result = 1;
  31.     else if (! thisCursor->isValid () && collectionCursor->isValid ())
  32.       result = -1;
  33.     else {
  34.     }
  35.   }
  36.   delete thisCursor;
  37.   delete collectionCursor;
  38.  
  39.   return result;
  40. }
  41.  
  42.