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 / SORTARRY.CPP < prev    next >
C/C++ Source or Header  |  1992-02-18  |  2KB  |  59 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  SORTARRY.CPP                                                          */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991                                  */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __SORTARRY_H )
  11. #include <SortArry.h>
  12. #endif  // __SORTARRY_H
  13.  
  14. #ifndef __STDLIB_H
  15. #include <stdlib.h>
  16. #endif
  17.  
  18. #if !defined( __IOSTREAM_H )
  19. #include <iostream.h>
  20. #endif  // __IOSTREAM_H
  21.  
  22. void SortedArray::add( Object& toAdd )
  23. {
  24.     if( toAdd.isSortable() )
  25.         {
  26.         if( lastElementIndex == upperbound )
  27.             {
  28.             reallocate( arraySize() + 1 );
  29.             }
  30.         int insertionPoint = lowerbound;
  31.         while( insertionPoint <= lastElementIndex &&
  32.                (Sortable&)objectAt( insertionPoint ) < (Sortable&)toAdd
  33.              )
  34.             insertionPoint++;
  35.  
  36.         insertEntry( insertionPoint );
  37.         setData( insertionPoint, &toAdd );
  38.         itemsInContainer++;
  39.         lastElementIndex++;
  40.         }
  41.     else
  42.         ClassLib_error( __ENOTSORT );
  43. }
  44.  
  45. void SortedArray::detach( Object& toDetach, DeleteType dt )
  46. {
  47.     int detachPoint = find( toDetach );
  48.     if( detachPoint != INT_MIN )
  49.         {
  50.         if( delObj(dt) )
  51.             delete ptrAt( detachPoint );
  52.         removeEntry( detachPoint );
  53.         itemsInContainer--;
  54.         if( detachPoint <= lastElementIndex )
  55.             lastElementIndex--;
  56.         }
  57. }
  58.  
  59.