home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c017 / 34.ddi / CSTRM.ZIP / BDRDEM1.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-23  |  1.2 KB  |  69 lines

  1.     // bdrdem1.cpp
  2.     // Demo of the two Binder constructors
  3.     
  4.     // Think of a Binder as an elastic array of void
  5.     // pointers.  The array can be accessed 
  6.     // interchangeably as a stack-queue-deque-list.
  7.  
  8.     #include <string.h>    
  9.     #include <iomanip.h>
  10.     #include <binder.hpp>
  11.  
  12.  
  13.     char *V[] = {
  14.         "Now is the time",
  15.         "for all programmers",
  16.         "to stop reinventing",
  17.         "the linked list!",
  18.         0
  19.     };
  20.     
  21.     void display(char *S)
  22.         { cout << S << endl; }
  23.  
  24.  
  25.     main()
  26.     {
  27.         Binder B1;
  28.  
  29.         for (int i = 0; B1.insQ(V[i]); i++);
  30.  
  31.         cout << "\n\nQueued vector:\n\n";
  32.  
  33.         while (B1.next())    // walk the list
  34.             cout << (char *)(voiD) B1 << endl;
  35.         
  36.         cout << "\n\nPress enter to continue ... ";
  37.         cin.get();
  38.         
  39.         
  40.         
  41.         BindeR B2 = new
  42.             Binder(Binder::ALL_FREE_DESTRUCT,3);
  43.         
  44.         for (i = 0; B2->insQ(strdup(V[i])); i++);
  45.         
  46.         cout << "\n\nQueued cloned vector "
  47.             << "limited to 3 nodes:\n\n";
  48.         
  49.         B2->forEach((BDRforEachBlocK)display);
  50.         
  51.         delete B2;
  52.         
  53.  
  54.  
  55.         Binder B3((voiDV)V);
  56.  
  57.         cout << "\n\nVector exploded into a binder:\n\n";
  58.         
  59.         while (B3++)    // iterate over the list
  60.             cout << (char *) B3.current() << endl;
  61.  
  62.         cout << "\n\nPress enter to quit ... ";
  63.         cin.get();
  64.  
  65.  
  66.  
  67.         return 0;
  68.     }
  69.