Leedwon

Untitled

May 1st, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. // metody klas Queue i Customer
  2.  
  3. #include "queue1.h"
  4. #include <cstdlib>
  5.  
  6. Queue::Queue(int qs) : qsize(qs)
  7. {
  8. front = rear = nullptr;
  9. items = 0;
  10. }
  11. Queue::~Queue()
  12. {
  13. while(front != nullptr)
  14. {
  15. Node * temp = front;
  16. front = front->next;
  17. temp = nullptr;
  18. }
  19. }
  20. bool Queue::isempty()
  21. {
  22. return items == 0;
  23. }
  24. bool Queue::isfull()
  25. {
  26. return items == qsize;
  27. }
  28. int Queue::queuecount() const
  29. {
  30. return items;
  31. }
  32. bool Queue::enqueue(const Item & item)
  33. {
  34. if (isfull())
  35. return false;
  36. Node * add = new Node;
  37. add->item = item;
  38. add->next = nullptr;
  39. items++;
  40. if (front == nullptr)
  41. front = add;
  42. else
  43. rear->next = add;
  44. rear = add;
  45. return true;
  46. }
  47. bool Queue::dequeue(Item & item)
  48. {
  49. if (front == nullptr)
  50. return false;
  51. item = front->item;
  52. items--;
  53. Node * temp = front;
  54. front = front->next;
  55. delete temp;
  56. if (items == 0)
  57. rear = nullptr;
  58. return true;
  59. }
  60. void Customer::set(long when)
  61. {
  62. processtime = std::rand() % 3 + 1;
  63. arrive = when;
  64. }
  65. bool operator>(const Queue & q1, const Queue & q2)
  66. {
  67. return q1.items > q2.items;
  68. }
  69. bool operator<(const Queue & q1, const Queue & q2)
  70. {
  71. return q2 > q1;
  72. }
Add Comment
Please, Sign In to add comment