     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 (Idone && !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	}

     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;                
    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:	} 


     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 TIArrayAsVectorlterator<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()) 
    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, TShouldOelete::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:	//    ,    
    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.6etItemsInContainer()  endl; //    
    66:	while ((sp = iterator++) != 0)       //    
    67:	  cout  " "  *sp;              //  	
    68:	cout  endl;                   //   
    69:	}
