home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_06_04 / v6n4052a.txt < prev    next >
Text File  |  1989-09-28  |  893b  |  43 lines

  1. #include <stdio.h>
  2. #include "q2.h"
  3.  
  4. #define LOOPS 20
  5.  
  6. main()
  7. {
  8.    int i;
  9.    int k;
  10.    qele_type next;
  11.    qele_type rval;
  12.  
  13.    /* initialization */
  14.    srand(12);
  15.    qele_cpy(next,q_NIL);
  16.  
  17.    for (i=0; i<LOOPS; i++){
  18.       k = rand();
  19.       k &= q_WRAP;
  20.       printf("\n%d positions unused",q_free());
  21.       printf("\nInserting %d items starting with %d",k,next);
  22.       while (k--){
  23.          if (q_put(next) == FULL) {
  24.             printf("\nQueue full");
  25.             break;
  26.             }
  27.          else
  28.             qele_incr(next);
  29.          }
  30.       k = rand();
  31.       k &= q_WRAP;
  32.       printf("\n%d positions used",q_bsy());
  33.       printf("\nRemoving %d items ",k);
  34.       while (k--){
  35.          if ((rval = q_get()) == EMPTY){
  36.             printf("\nQueue Empty");
  37.             break;
  38.             }
  39.          else printf("\n    %d",rval);
  40.          }
  41.       }
  42. }
  43.