home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP30-1.ZIP / CLASSSRC.ZIP / BSORTARY.CPP < prev    next >
C/C++ Source or Header  |  1992-02-18  |  2KB  |  63 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  BSORTARY.CPP                                                          */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991                                  */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( TEMPLATES )
  11. #define TEMPLATES
  12. #endif
  13.  
  14. #if !defined( __SORTABLE_H )
  15. #include <Sortable.h>
  16. #endif  // __SORTABLE_H
  17.  
  18. #if !defined( __ARRAYS_H )
  19. #include <Arrays.h>
  20. #endif  // __ARRAYS_H
  21.  
  22. void BI_ISObjectVector::add( Object _FAR *o )
  23. {
  24.     if( count_ >= lim )
  25.         resize( count_+1 );
  26.     unsigned loc = count_++;
  27.     while( loc > 0 && *(Sortable _FAR *)o < *(Sortable _FAR *)(data[loc-1]) )
  28.         {
  29.         data[loc] = data[loc-1];
  30.         loc--;
  31.         }
  32.     data[loc] = o;
  33. }
  34.  
  35. unsigned BI_ISObjectVector::find( void _FAR * obj ) const
  36. {
  37.     unsigned lower = 0;
  38.     unsigned upper = count_-1;
  39.     if( count_ != 0 )
  40.         {
  41.         while( lower < upper && upper != UINT_MAX )
  42.             {
  43.             unsigned middle = (lower+upper)/2;
  44.             if( *(const Sortable _FAR *)(data[middle]) ==
  45.                 *(const Sortable _FAR *)obj
  46.               )
  47.                 return middle;
  48.             if( *(const Sortable _FAR *)(data[middle]) <
  49.                 *(const Sortable _FAR *)obj
  50.               )
  51.                 lower = middle+1;
  52.             else
  53.                 upper = middle-1;
  54.             }
  55.         }
  56.     if( lower == upper &&
  57.         *(const Sortable _FAR *)(data[lower]) == *(const Sortable _FAR *)obj
  58.       )
  59.         return lower;
  60.     else
  61.         return UINT_MAX;
  62. }
  63.