home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / clobss.pak / SORTARRY.CPO < prev    next >
Text File  |  1997-07-23  |  2KB  |  64 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  SORTARRY.CPP                                                          */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991, 1993                            */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __STDLIB_H )
  11. #include <stdlib.h>
  12. #endif    // __STDLIB_H
  13.  
  14. #if !defined( __IOSTREAM_H )
  15. #include <iostream.h>
  16. #endif  // __IOSTREAM_H
  17.  
  18. #if !defined( __SORTARRY_H )
  19. #include "classlib\obsolete\sortarry.h"
  20. #endif  // __SORTARRY_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( int loc, DeleteType dt )
  46. {
  47.     if( loc != INT_MIN )
  48.         {
  49.         if( delObj(dt) )
  50.             delete ptrAt( loc );
  51.         removeEntry( loc );
  52.         itemsInContainer--;
  53.         if( loc <= lastElementIndex )
  54.             lastElementIndex--;
  55.         }
  56. }
  57.  
  58. void SortedArray::detach( Object& toDetach, DeleteType dt )
  59. {
  60.     int detachPoint = find( toDetach );
  61.     detach( detachPoint, dt );
  62. }
  63.  
  64.