     16 

       Borland 

        Borland   ,  
         . 
    ,      
,    .  ,  
 -,        
   ,      
  . 
            Borland,   
      . 
       Borland C++ 3.1    : 
   ,     C++.   4.0 
     ,   
   .    ,   
   ,  ,     
,     15. 
            DOS, 
EasyWin  Windows.    ,    , 
   DOS-  EasyWin-,     
,     ,       Windows. 

     
      4.0       
OBSOLETE,    INCLUDE\CLASSLIB,     
  LIB\SLETE.LIB,       
   .      
 . 


         

               
 . ,      (-
    )    .  
    ,       
      .   
         
,    . 

       

           ().   
   ,       , 
 Push()  (),       . 
        .   
       .     
, ,        
      . 
            .   
    ().    
,  ,     ,   
   . ,     
()     ().        
   . 

     
     C++,  ,   ,     
,   .      
   .      ,    
   .     ,  
       [].  
      ,    
   .
 
             .  
     TArrayAsVector.     
,      (),   (). 
    "". 
       Borland         
  .      
,    ,    ,  
 : TClass<T>,      . , TStackAsList<long> 
       ,             
            ; TQueueAsVector<MyDataType>  
  ,       MyDataType 
        . 
         (,   ..), 
  (,   )   .  
           
.     . 

               

       ,    .  
      ,   
 INCLUDE\CLASSLIB  C:\BC45. ,    
  ,     STACKS.H. 

    #include <classlib\stacks.h>	

          ,   
 ,  TStackAsVector.    
     45.	

    TStackAsVector(unsigned max = DEFAULT_STACK_SIZE); 

          ,    
 ,    ,   
   ,     
RESOURCE.H.      ,   
   . ,     
      : 

    TStackAsVector<double> myStack(100); 

          myStack    
TStackAsVector,        
.        
   ,      
 ,       
 . 

     16.    Borland	425 

                
     -,    
  -.   16.1   
,    TStackAsVector. 

     
       STACKED.CPP  DOS-  Easy Win-, 
          
  BIDSx.LIB (x   ):
    bcc stacked bidss.lib 
    BIDS   Borland International Data Structure ( 
 Borland International).       , 
    : S (small -),  (compact  
),  (medium  ), L (large  ),  (huge  )  
Hflat   32-). 
        EasyWin-    
   <ALT+F10>   TargetExpert.  Target Type 
 EasyWin   Large  Small Target Model (   
 ,   Windows-    Large). 
,    Class Library  Standard Libraries.  
      . 


     16.1.   STACKED.CPP ( TStackAsVector) 

    1:	#include <iostream.h> 
    2:	#include <classlib\stacks.h> 
    3: 
    4:	#define TRUE 1 
    5:	#define FALSE 0                 
    6:	
    7:	//     
    8:	TStackAsVector<double> myStack(100);     
    9:
    10:	int nain()        
    11:	{                  
    12:	double d;      
    13:	int done = FALSE; 
    14: 
    15:	//        
    16:	while (!done && !myStack.IsFull()) { 
    17:	  cout << "Enter double value (0.0 to quit): "; 
    18:	  cin >> d;       //    
    19:	  if (d == 0.0) 
    20:	   done = TRUE;    //   while
    21:	else 
    22:	   myStack.Push(d); //  d   
    23:	} 
    24 
    25	//     
    26	int n = myStack.GetITemsInContainer();            
    27	cout << endl << "Number of objects: " << n << endl;   
    28	if (n > 0) 
    29	   cout << "Top of stack: " << myStack.Top() << endl << endl; 
    30 
    31	//        
    32	while (!myStack.IsEmpty()) 
    33	  cout << myStack.Pop() << endl; 
    34 
    35	return 0; 
    36	}

      STACKED       
   .    0,    
,   ,  ,    .  
      ,    
  .       
 "    ",     
 .  . 16.1    :	


    426      IV.   


    Enter double value (0.0 to quit)  9.9 
    Enter double value (0.0 to quit)  3,14159 
    Enter double value (0.0 to quit)  -88.55 
    Enter double value (0.0 to quit)  4.32 
    Enter double value {0.0 to quit)  6.9 
    Enter double value (0.0(to quit)  0 
    Number of objects: 5 
    Top of stack: 6.9 
    6.9 
    4.32 
    -88.55 
    3.14159 
    9.9
 
    . 16.1.    STACKED 

     ,      ,  
 ,    IsFull().  ,   
,     IsEmpty().     
IsFull()       : 

    if  (ImyStack.IsFull()) 
       myStack.Push; 

     d   double.       
,     ,     
 ,    , .   
    ,      , 
   . 
           (),   
   .  ()  ,   
.          , 
    .     IsEmpty()  
      : 

    if  (!myStack.IsEmpty())	
       d = myStack.Pop(); 

         ,    , 
    (),     
    ,        . 
 ,    IsEmpty()      
,   "" : 

    if ( !myStack.IsEmpty() ) 
       d = myStack.Top(); 

       ,   ,    
 GetItemsInContainer().     : 

    int n = myStack.GetltemsInContainer();	

           , 
,  GetltemsInContainer().     ,   
      .       
Push(), ()  ().	

       

             
,       ,    
      ,  ,   
  . ,   TStackAsVector   .  
  TMStackAsVector   ,  Push(), 
()  ().      ,  ,  
 TStackAsVector. 

     
       ,   ,   
  .        , 
       ,   
  . 

             
  .       
 .        
.          
,    -,       
    ,       . 

     16.    Borland     427 

           :	
   
     [] [] [s] [] 

           ().   
      ,    (S) 
       (I).    , 
  (Array)   (Stack).      As,  
     ,   ,  , 
 (List),   (DoubleList)    
 . ,   ""    
 .  ,  ,   
Iterator, ,        
  .
              
.          , 
 ,  ,    
.      .    
       . ,   
 TStackAsHashTable,     (  
  )   - (   
 ). 
     . 16.1       
   ,     
,     . , Deque  
  DoubleList  Vector.   ,   
     TDequeAsDoubleList  
TDequeAsVector.   ,   TDequeAsHashTable 
 .       BinarySearchTree. 

     16.1.    

           		 	 		-		 
                       	     		 		
							
    Array ()		ARRAYS.H								 
    Bag ()	BAGS.H								 
    Deque (   
      )	DEQUES.H								 
    Dictionary ()	DICT.H					 
    Queue ()		QUEUES.H								 
    Set ()		SETS.H					                              
    Stack ()			STACKS.H								 

     . 16.2    ,    . 16.1,   
 ,          
 . ,  . 16.2 ,    
Stack   List, ,    
     TStackList.     , 
 Vector      , 
     . 

     16.2.    

      				Array	Bag  Deque	Dictionary	Queue	Set	Stack 
				

    	BINIMP.H
   
    	DLISTIMP.H							
   -		HASHIMP.H					 	
   	        	LISTIMP.H									 
   	         	VECTIMP.H									


    428      IV.   

     . 16.3    ,   . 16.1  16.2,  
   .    
      .  TIStackVector   
  ,    .   
   .   I (,  TStackVector) 
   .  S   
. ,  TSArrayAsVector    , 
   ,  TISArrayAsVector   
   ,    . 

     16.3.   

    	           

    			    
    I			   ( I    ) 
    IS		     
    			   
    MC		       
    MI		      
    MIC		  ,       
    MIS		  ,     
    MS		     
    S			  

              
  . (     , , , 
     Star Trek). ,   
TMQueueAsVector      TQueueAsVector. 
        
    .   
    . 
             
TStandardAllocator,     ALLOCSTR.H.   
   new, new[], delete  delete[],   
Borland C++      malloc()  free().   
     ,      
-,   TStandardAllocator,       
    . 
    ,          
        
     (.  PERSIST.CPP  
     15,     
).        
  , , ,    
 ,        
 . 

     
            . 
         
.     : "   
    ".  ,    
       ==  <.  
  ,   III. 

            
 ,       ( 
    ,       
). ,     Element,  
" " .       
TMDoubleListElement  TMListElement.      
,   -.      
Element     .    
  .

     16.    Borland     429 

       , Imp,  .  , , 
    Imp,     , 
    . ,  
TDoubleListImp   .     Imp 
   , ,     
    .     
  ,  TDequeAsDoubleList,  
 TDoubleListImp,     . 
        , Iterator, ,   
         
.      ,   
. ,  TDequeAsVectorIterator    , 
   TDequeAsVector.  ,   
Imp,     . ,  
TDoubleListIteratorImp     ,   
 TDoubleListImp. 
    ,    , TShouldDelete, ""   
.      ,    , 
    ,   ,    
   .   " "    
 ,      .	

     ""  

    ,          
 ,        
.        
      .	

           

       ,  ,    
 ( )   (). ,  
     I,  TIQueueAsVector,  
 ,     .   I (TQueueAsVector, 
)    .   16.2 
    . 

     16.2.  DIRECT.CPP (     ) 

     1:	#include <iostream.h>                                           
     2:	#include <cstring.h>                                              
     3:	#include <classlib\arrays.h> 
     4:	
     5:	#define TRUE 1 
     6:	#define FALSE 0 
     7: 
     8: 	//          
     9:	TArrayAsVector<string> dStrings(10);                           
    10:	TIArrayAsVector<string> iStrings(10); 
    11:	
    12:	int main() 
    13:	{ 
    14:	  int done = FALSE; //    while 
    15:	  int i;         //    for 
    16:	  string s;        //    
    17:	  char buf[81];    //    
    18: 
    19:	  while (!done) { 
    20:	    cout << "Enter a string: ";   //    
    21:	    cin.getline(buf, sizeof(buf)); //    
    22:	    s = buf;               //    string 
    23:	    if (s.length() == 0)       //     
    24:	      done = TRUE;          //   -   while 
    25:	    else {                  // .... 
    26:	     dStrings.Add(s);      //    
    21:	     iStrings.Add(new string(s)); //     
    28:	    } 
    29:	  } 
    30: 
    31:	  //       
    32:	  cout << endl;. 
    33:	  cout << "Direct string array" << endl;                
    

    430	 IV.   


   34:	  for (i = 0; i < dStrings.GetItemsInContainer(); i++ )
   35:	    cout << dStrings[i] << endl;		
   36: 
   37:	  //      		
   38:	  cout << endl;		
   39:	  cout << "Indirect string array" << endl;		
   40:	  for ( i = 0; i < iStrinfls.GetltemsInContainer(); i++ ) 
   41:	    cout << *iStrings[i] << endl; 
   42:		 
   43:	  return 0; 
   44:	} 

        ,    
 string,       CSTRING.H. 
,    ,   
 : 

    TArrayAsVector<string> dStrings(10); 

    ,    ,    
,  ,      , 
    new: 

    TIArrayAsVector<string> iStrings(10); 

     , dStrings  iStrings,     
 .    ,   dStrings   
 ,   iStrings     . 
       ,     
.        s 
     dStrings      
Add()  : 

    dStrings.Add(s); 

     Add()      .   
    Add(),      
    .      
iString    	

    iString.Add(new string(s)); 

          s   
 Add().   s    ,  
   .      
       
 .         
   ,    . , 
,       
new     .	 
          ,   
 GetItemsInContainer(),    .   
     for       
  :

    for (i=0;   i < dStrings.GetItemsInContainer();   i++)	
       cout < dStrings[i]  endl; 

           ,  
   ,     :

    for ( i= 0 ;  i < iStrings.GetItemsInContainer();  i++) 
      cout << *iStrings[i] << endl;         //    

     ""   ,     
   .     , 
   iStrings[i]     . 

     

           
.        
,     ,    . 
         ""      
 . ,        
,        ,  
 ().     ""    
    . 

     16.    Borland	431 

      ,       
  .     DIRECT.CPP,   16.3   
  ,        TIQueueAsDoubleList. 

     16.3.   ITERATE.CPP ( ) 

    1: #include <iostream.h> 
    2: #include <cstring.h> 
    3: #include <classlib\queues.h> 
    4: 
    5: //      
    6  TIQueueAsDoubleList<string> iQueue;	
    7: 
    8: int main()	
    9: {	
    10:	//                                      
    11:	iQueue.Put(new string("Line up")); 
    12:	iQueue.Put(new string("for the"));                                    
    13:	iQueue.Put(new string("Magical"));         
    14:	iQueue.Put(new string("Mystery"));   
    15:	iQueue.Put(new string("Tour"  ));                                      
    16:	
    17:	//      iQueue                    
    18:	TIQueueAsDoubleListIterator<string> iterator(iOueue); 
    19: 
    20:	//       
    21:	cout << "\nWalk the queue using an iterator:" << endl; 
    22:	cout << "" << endl; 
    23:	while (iterator != 0) { 
    24:	   cout << *iterator.Current() << endl; 
    25:	   iterator++; 
    26:	} 
    27:	 
    28:	//                 
    29:	cout << "\nExtract queue objects:" << endl;               
    30:	cout << "" << endl; 
    31:	while ( !iQueue.IsEmpty() ) { 
    32:	   string *p = iQueue.Get();                                     
    33:	   cout << *p << endl; 
    34:	   delete p; 
    35:	}                                                                      
    36:	
    37:	return 0; 
    38:  }

              
iQueue.     (    TI),   
    : 

    TIQueueAsOoubleList<string> iQueue;	

      ,       
  new      .  
       , 
  new, - Put()   . 
 Put()      ,    Add()  
: 

    iQueue.Put(new string("Magical")); 
    iQueue.Put(new string("Mystery")); 

         ,    
   TIQueueAsDoubleList.     
    Iterator: 

    TIQueueAsDoubleListIterator<string> iterator(iQueue); 

      ,       ,  
           
typedef, :	

    typedef TIQueueAsDoubleListIterator<string> TIterator; 

     typedef ,   TIterator    
"" .      
 (    ): 

    TIterator iterator(iQueue); 

      ,    (   iterator) 
 TIQueueAsDoubleListIterator<string>.   iQueue  
     .    
      iQueue. 

    432	 IV.   

     ,  iterator.Current()    
 Queue      .   , 
    (  ,   
  ). 
           ,    
 .    ,   - 
     int().  ,   
   ,   ,  
   int()      
.      (),    
   . 
           "  ", 
     ,    :	

    while (iterator != 0) {	//    int()       
       cout << *iterater.Current() << nedl;	//                  
       iterator++;           //      

          ++ ( ,  
 ).     ,   
  iterator++ ( ++iterator)    
     .  ++   
  ,   ,        
  .       
     Restart()       
 :	

    iterator.Restart();      //     
    string *p;               //     

         while ( -   ) 
   : 

    while ( = iterator++)   //       
    cout << * << endl;      //  ,    

        while     
  ,       
.        
    .       
   . 
        , ,    
 "possibly incorrect assignment" ("  
"),   =      
      ==.   ,  
  =    ,     
,  ,  .     
 ,     ,  
   ,    : 

    while ( (  = iterator++ ) != 0 )     
         cout << * << endl; 

      ,   ,  ,  Restart()  
  int()  ++.     
  . ,    
  Restart   : 

    void   Restart(unsigned start,   unsigned stop); 

       Restart()    ,   
     ,   -. 

      

           ,    
 .    .   ,     
  .      (   
).   ,       
,     new,    ,  
   ,     ,   
 .     , ""    
  "" .     
,  ,       
.          
  . 
         ,     
,    ?  ,    
,     ,     
.      ,    
      .	

     16.    Borland	433 


        

       ,   ,  
TIArrayAsVector,   ,    TShouldDelete. 
,    ,    
 : 

    TIArrayAsVector<string> stuff(100); 

      ,   stuff   (    ), 
   OwnsElements(),    TShouldDelete:

    cout << stuff.OwnsElements() << endl;	

   OwnsElements()   (1),     , 
  (0),  . 
             
     OwnsElement(),    
.     TRUE  FALSE.  
  : 

    #define TRUE 1 
    #define FALSE 0	

    ...
    stuff.OwnsElements(FALSE);  //   	

         stuff ,    
  .      
  OwnsElementsO   TRUE: 

    stuff.OwnsElements(TRUE);	


     
            ,  
       TShouldDelete.     
  : 
    TArrayAsVector<strmg> stuff2(100); , 
           stuff2: 
    stuff2.OwnsElements(TRUE);	// !!!
             
"'OwnsElements' is not a member of 'TArrayAsVector<string>'" ( 'OwnsElements'  
  'TArrayAsVector<string>' ),   ,  
 ,     TShouldDelete.     
    ,     . 


        

             
 -        
 , ,     .   16.4 
   . 

     16.4.  OWNER.CPP (  ) 

    1:	#include <iostream.h>               
    2:	#include <cstring.h>           
    3:	#include <classlib\arrays. h>                            
    4: 
    5:	//     
    6:	typedef TIArrayAsVector<string> TContainer; 
    7: 
    8.	typedef TIArrayAsVectorIerator<string> TIterator;	
    9:	//     	
    10:	void ShowMe(const char *msg, TContainer &cr);
    11:		
    12:	int main()	
    13:	{ 
    14:	  TContainer *cp;   //    
    15:	  string s("Tulips"); //  	
    16: 
    17:	  //        
    18:	   = new TContainer(10, 0, 10);	
    19:	  cout << endl;                                  
    20:	  cout << "Array owns objects: ";	
    21:	  if (cp->OwnsElements()) 


    434	 IV.   

    22:	    cout << "TRUE" << endl;   
    23:	  else               
    24:	    cout << "FALSE" << endl;	
    25:		
    26:	//      	
    27:	cp->Add(new string("Tip")); 
    28:	cp->Add(new string("Toe")); 
    29:	cp->Add(new string ("Through"));	
    30:	cp->Add(new string("The"));	
    31:	cp->Add(&s); // !!! !!!   
    32:	ShowMe("Original array: ", *cp);	
    33: 
    34:	//         
    35:	cp->Detach(2, TShouldDelete::Delete);  
    36:	ShowMe("After Detach(2, Delete)", *cp);  
    37: 
    38:	//    ,        
    39:	cp->Detach(&s, TShouldDelete::NoDelete);           
    40:	ShowMe("After Detach(&s, NoDelete)", *cp); 
    41: 
    42:	//    , ,  	
    43:	int n = cp->GetItemsInContainer();	
    44:	cp->Detach(n - 1, TShouldDelete::DefDelete);	
    45:	ShowMe("After Detactj(n - 1, DefDelete)", *cp);	
    46: 
    47:	//     , , ,   
    48:	Cp->Flush(); 
    49:	ShowMe( "After Flush()", *cp);	
    50:		
    51:	//  .   ???	
    52:	delete cp; 
    53:		
    54:	return 0;     
    55:	}             
    56: 
    57:	//    r,    
    58:	void ShowMe(const char *msg, TContainer &cr) 
    59:	{ 
    60:	TIterator iterator(cr); //     
    61:	string *sp;          //     
    62: 
    63:	cout << endl << msg << endl;         //   
    64:	cout << "Items in container = ";       //  	
    65:	cout << cr.GetItemsInContainer() << endl; //    
    66:	while ((sp = iterator++) != 0)       //    
    67:	  cout << " " << *sp;              //  	
    68:	cout << endl;                   //   
    69:	}
 
             
 .  TContainer     , 
   .  TIterator     
.       TContainer,    
 new   :	

    TContainer *cp; 
    cp = new TContainer(10,  0,  10);	

        ,   ,  
 ,   (  ),   
       :	

    cp->Add(new string("Tip")); 

     ,        
 s,    :	

    cp->Add(&s);    // !!!	

       ,      . , 
          
,     ,   , 
    .   ,     
   .      
      ,   
            , 
   .	

     16.    Borland	435 

             : 

    cp->Detach( 2, TShouldDelete::Delete); 

     2 ,        . 
        . 
 TShouldDelete::Delete ,       
   . 
      ,         
. ,       
  : 

    cp->Detach(&s,  TShouldDelete::NoDelete); 

             
      ,     
  . ,       
     s,  ,  
,  :	

    cp->Flush(); 

       Flush()   ,   
.       ""  , 
    ,     
,       . 
       ,     ,   
 . ,      , 
  n  :

    cp->Detach(n-1, TShouldDelete::DefDelete); 

      Detach  DefDelete  ,  
      ,   
 .      ,    
 ,       . 
    ,     ,    
       new: 

    delete cp; 

      ,         
 ,   .      , 
    ,   .     
  ,       ,  
   . 

    1.   Flush()   . 
    2.         ,  
  Flush(). 

     ,      ,  , 
      Flush(),     
   .     
      Flush().  
        OWNER.CPP: 

    template <class T> class TIMyArrayAsVector : 
         public TIArrayAsVector<T> { 
    public: 
       TIMyArrayAsVector(int upper,   int lower = 0,   int delta = 0)  : 
         TIArrayAsVector<T>(upper,  lower,  delta)  { } 
       ~TImyArrayAsVector  { Flush();  }
     };

       TIMyArrayAsVector    . 
   Flush()     DefDelete. 
,    ,    
 ,        . 
           OWNER.CPP,   
typedef  TContainer ,   .    
     . 

    typedef TIMyArrayAsVector<string> TContainer;        

   
    
             
  -.    ,  
TContainer,    , 6    
 ,      typedef.   
  typedef    .     
 ,    ,    . 
    

    436	 IV.   

     

          Borland    
       .  
 Borland C++ 3.1    :    
,    C++.   4.5    
     . (   
  ,        .) 
                
DOS, EasyWm  Windows.  16-  32- . 
             
,    . 
            
 ,     . 
                . 
,  TArrayAsVector        
   . 
               
     ,    
 .       ,     
 ,   ,    .   
    . 
               
 ,  , , , , 
,   . 
           ,  
  ,    :  
 ,  , -,   . 
            ,  
   . 
           ""   . 
        
  . 
        TShouldDelete      
.     ,     
,     .    ,  
  ,       , 
   . 
             TShouldDelete. 
     TShouldDelete.      
   . 


     16.    Borland	437 
