home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IASRTBAG.C < prev    next >
Text File  |  1993-09-22  |  3KB  |  70 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 >
  14. IBoolean IASortedBag < Element >::
  15. operator == (IASortedBag < Element > const& collection) const
  16. { if (numberOfElements () != collection.numberOfElements ())
  17.     return False;
  18.  
  19.   ICursor *cursor1 = newCursor ();
  20.   IBoolean result = True;
  21.   for (cursor1->setToFirst ();
  22.        cursor1->isValid ();
  23.        setToNextDifferentElement (*cursor1)) {
  24.     if (collection.numberOfOccurrences (elementAt (*cursor1)) !=
  25.         numberOfOccurrences (elementAt (*cursor1))) {
  26.       result = False;
  27.       break;
  28.     }
  29.   }
  30.   delete cursor1;
  31.   return result;
  32.  
  33. }
  34.  
  35. template < class Element >
  36. IBoolean IASortedBag < Element >::
  37. operator != (IASortedBag < Element > const& collection) const
  38. { return ! operator == (collection);
  39. }
  40.  
  41. template < class Element >
  42. long IASortedBag < Element >::
  43. compare (IASortedBag < Element > const& collection,
  44.          long (*comparisonFunction) (Element const&, Element const&)) const
  45. { long result = 0;
  46.   ICursor *thisCursor = newCursor ();
  47.   ICursor *collectionCursor = collection.newCursor ();
  48.  
  49.   for (thisCursor->setToFirst (), collectionCursor->setToFirst ();
  50.        result == 0 && thisCursor->isValid () && collectionCursor->isValid ();
  51.        thisCursor->setToNext (), collectionCursor->setToNext ()) {
  52.     result = (*comparisonFunction) (this->elementAt (*thisCursor),
  53.                                       collection.elementAt (*collectionCursor));
  54.   }
  55.  
  56.   if (result == 0) {
  57.     if (thisCursor->isValid () && ! collectionCursor->isValid ())
  58.       result = 1;
  59.     else if (! thisCursor->isValid () && collectionCursor->isValid ())
  60.       result = -1;
  61.     else {
  62.     }
  63.   }
  64.   delete thisCursor;
  65.   delete collectionCursor;
  66.  
  67.   return result;
  68. }
  69.  
  70.