// File: genq.h
//
// A generic queue class

#ifndef _genq_h
#define _genq_h


class QCell{
friend class GenQ ;

public:
   void  *data ;  // points to real data
   QCell *next ;  // points to next QCell on the queue
private:
   QCell()  { data = NULL ; next = NULL ; }
   ~QCell() { /* do nothing */ }
} ;


class GenQ {

public:
   typedef int (* GQcmp) (void *, void *) ;
   typedef void (* GQprt) (void *) ;

   GenQ(GQcmp, GQprt) ;     // constructor requires client supplied functions
   ~GenQ() ;                // destructor

   void enqueue(void *) ;   // Add item to end of the queue
   void *dequeue() ;        // Return and delete item from the front of queue
   void *peek() ;           // Look at first item
   void print() ;           // Print the entire list
   void remove(void *) ;    // remove items equal to given one

   int length() { return len ; }

protected:
   QCell dummy ;            // header for the Queue. not a pointer!
   QCell *last ;            // last QCell in the Queue
   int   len ;              // number of items in the queue

   QCell *newcell() ;       // return pointer to new QCell

private:
   GQcmp cmp ;              // pointer to client supplied comparison function
   GQprt prnt ;             // pointer to client supplied print routine
} ;


#endif
