1
0

queue.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* queue.h -- interface for a queue */
  2. #ifndef _QUEUE_H_
  3. #define _QUEUE_H_
  4. #include <stdbool.h>
  5. // INSERT ITEM TYPE HERE
  6. // FOR EXAMPLE,
  7. //typedef int Item; // for use_q.c
  8. // OR typedef struct item {int gumption; int charisma;} Item;
  9. // OR (for mall.c)
  10. /**/
  11. typedef struct item
  12. {
  13. long arrive; // the time when a customer joins the queue
  14. int processtime; // the number of consultation minutes desired
  15. } Item;
  16. /**/
  17. #define MAXQUEUE 10
  18. typedef struct node
  19. {
  20. Item item;
  21. struct node * next;
  22. } Node;
  23. typedef struct queue
  24. {
  25. Node * front; /* pointer to front of queue */
  26. Node * rear; /* pointer to rear of queue */
  27. int items; /* number of items in queue */
  28. } Queue;
  29. /* operation: initialize the queue */
  30. /* precondition: pq points to a queue */
  31. /* postcondition: queue is initialized to being empty */
  32. void InitializeQueue(Queue * pq);
  33. /* operation: check if queue is full */
  34. /* precondition: pq points to previously initialized queue */
  35. /* postcondition: returns True if queue is full, else False */
  36. bool QueueIsFull(const Queue * pq);
  37. /* operation: check if queue is empty */
  38. /* precondition: pq points to previously initialized queue */
  39. /* postcondition: returns True if queue is empty, else False */
  40. bool QueueIsEmpty(const Queue *pq);
  41. /* operation: determine number of items in queue */
  42. /* precondition: pq points to previously initialized queue */
  43. /* postcondition: returns number of items in queue */
  44. int QueueItemCount(const Queue * pq);
  45. /* operation: add item to rear of queue */
  46. /* precondition: pq points to previously initialized queue */
  47. /* item is to be placed at rear of queue */
  48. /* postcondition: if queue is not empty, item is placed at */
  49. /* rear of queue and function returns */
  50. /* True; otherwise, queue is unchanged and */
  51. /* function returns False */
  52. bool EnQueue(Item item, Queue * pq);
  53. /* operation: remove item from front of queue */
  54. /* precondition: pq points to previously initialized queue */
  55. /* postcondition: if queue is not empty, item at head of */
  56. /* queue is copied to *pitem and deleted from */
  57. /* queue, and function returns True; if the */
  58. /* operation empties the queue, the queue is */
  59. /* reset to empty. If the queue is empty to */
  60. /* begin with, queue is unchanged and the */
  61. /* function returns False */
  62. bool DeQueue(Item *pitem, Queue * pq);
  63. /* operation: empty the queue */
  64. /* precondition: pq points to previously initialized queue */
  65. /* postconditions: the queue is empty */
  66. void EmptyTheQueue(Queue * pq);
  67. #endif