Listing 9 a test program for comqs as a queue of str

//
// strtst6.cpp - test comq6 using str elements
//

#include <iostream.h>

#include "comq6.h"
#include "comstr6.h"
#include "showheap.h"

ostream &operator<<(ostream &os, comq &q)
   {
   comstr *ps;
   comq::iterator cqi(q);
   while ((ps = (comstr *)cqi.next()) != 0)
          os << ' ' << *ps;
   return os;
   }
#define DIM(a) (sizeof(a)/sizeof(a[0]))

void test()
   {
   char c;
   size_t qn;
   comstr qe;
   comq q[4];
   while (cin >> c)
      {
      showheap();
      if (c == 'q')
         break;
      if (c == 'a')
         {
         cin >> qn >> qe;
         if (qn >= DIM(q))
            cout << "no such queue\n";
         else
            q[qn].append(qe);
         }
      else if (c == 'c')
         {
         cin >> qn;
         if (qn >= DIM(q))
            cout << "no such queue\n";
         else
            q[qn].clear();
         }
      else if (c == 'r')
         {
         cin >> qn;
         if (qn >= DIM(q))
            cout << "no such queue\n";
         else if (q[qn].remove(qe))
            cout << "removed" << qe << '\n';
         else
            cout << "q[" << qn << "] is empty\n";
         }
      else
         continue;
      for (size_t i = 0; i < DIM(q); ++i)
         cout << i << ':' << q[i] << '\n';
      }
   }

int main()
   {
   showheap();
   test();
   showheap();
   return 0;
   }

// End of File