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

#ifndef _genq_h
#define _genq_h

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

class QCell{
friend class GenQ ;
private:
   void  *data ;  // points to real data
   QCell *next ;  // points to next QCell on the queue

   QCell()  { data = NULL ; next = NULL ; }

   ~QCell() { /* do nothing */ }
} ;


class GenQ {

public:
   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 ; }

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

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


#endif
