home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_06 / saks / strtst2.cpp < prev   
Encoding:
C/C++ Source or Header  |  1994-04-08  |  1.0 KB  |  71 lines

  1. Listing 6 - A test program for a queue of str
  2.  
  3. //
  4. // strtst2.cpp - test strq1
  5. //
  6.  
  7. #include <iostream.h>
  8.  
  9. #include "strq2.h"
  10. #include "showheap.h"
  11.  
  12. #define DIM(a) (sizeof(a)/sizeof(a[0]))
  13.  
  14. void test()
  15.     {
  16.     char c;
  17.     size_t qn;
  18.     str qe;
  19.     strq q[4];
  20.     while (cin >> c)
  21.         {
  22.         showheap();
  23.         if (c == 'q')
  24.             break;
  25.         if (c == 'a')
  26.             {
  27.             cin >> qn >> qe;
  28.             if (qn >= DIM(q)) 
  29.                 cout << "no such queue\n";
  30.             else
  31.                 q[qn].append(qe);
  32.             }
  33.         else if (c == 'c')
  34.             {
  35.             cin >> qn;
  36.             if (qn >= DIM(q))
  37.                 cout << "no such queue\n";
  38.             else
  39.                 q[qn].clear();
  40.             }
  41.         else if (c == 'r')
  42.             {
  43.             cin >> qn;
  44.             if (qn >= DIM(q))
  45.                 cout << "no such queue\n";
  46.             else if (q[qn].remove(qe))
  47.                 cout << "removed " << qe << '\n';
  48.             else
  49.                 cout << "q[" << qn << "] is empty\n";
  50.             }
  51.         else
  52.             continue;
  53.         for (size_t i = 0; i < DIM(q); ++i)
  54.             {
  55.             cout << i << ':';
  56.             q[i].print(cout);
  57.             cout << '\n';
  58.             }
  59.         }
  60.     }
  61.  
  62. int main()
  63.     {
  64.     showheap();
  65.     test();
  66.     showheap();
  67.     return 0;
  68.     }
  69.  
  70.  
  71.