queue.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // queue.h -- interface for a queue
  2. #ifndef QUEUE_H_
  3. #define QUEUE_H_
  4. // This queue will contain Customer items
  5. class Customer
  6. {
  7. private:
  8. long arrive; // arrival time for customer
  9. int processtime; // processing time for customer
  10. public:
  11. Customer() : arrive(0), processtime (0){}
  12. void set(long when);
  13. long when() const { return arrive; }
  14. int ptime() const { return processtime; }
  15. };
  16. typedef Customer Item;
  17. class Queue
  18. {
  19. private:
  20. // class scope definitions
  21. // Node is a nested structure definition local to this class
  22. struct Node { Item item; struct Node * next;};
  23. enum {Q_SIZE = 10};
  24. // private class members
  25. Node * front; // pointer to front of Queue
  26. Node * rear; // pointer to rear of Queue
  27. int items; // current number of items in Queue
  28. const int qsize; // maximum number of items in Queue
  29. // preemptive definitions to prevent public copying
  30. Queue(const Queue & q) : qsize(0) { }
  31. Queue & operator=(const Queue & q) { return *this;}
  32. public:
  33. Queue(int qs = Q_SIZE); // create queue with a qs limit
  34. ~Queue();
  35. bool isempty() const;
  36. bool isfull() const;
  37. int queuecount() const;
  38. bool enqueue(const Item &item); // add item to end
  39. bool dequeue(Item &item); // remove item from front
  40. };
  41. #endif