Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // metody klas Queue i Customer
- #include "queue1.h"
- #include <cstdlib>
- Queue::Queue(int qs) : qsize(qs)
- {
- front = rear = nullptr;
- items = 0;
- }
- Queue::~Queue()
- {
- while(front != nullptr)
- {
- Node * temp = front;
- front = front->next;
- temp = nullptr;
- }
- }
- bool Queue::isempty()
- {
- return items == 0;
- }
- bool Queue::isfull()
- {
- return items == qsize;
- }
- int Queue::queuecount() const
- {
- return items;
- }
- bool Queue::enqueue(const Item & item)
- {
- if (isfull())
- return false;
- Node * add = new Node;
- add->item = item;
- add->next = nullptr;
- items++;
- if (front == nullptr)
- front = add;
- else
- rear->next = add;
- rear = add;
- return true;
- }
- bool Queue::dequeue(Item & item)
- {
- if (front == nullptr)
- return false;
- item = front->item;
- items--;
- Node * temp = front;
- front = front->next;
- delete temp;
- if (items == 0)
- rear = nullptr;
- return true;
- }
- void Customer::set(long when)
- {
- processtime = std::rand() % 3 + 1;
- arrive = when;
- }
- bool operator>(const Queue & q1, const Queue & q2)
- {
- return q1.items > q2.items;
- }
- bool operator<(const Queue & q1, const Queue & q2)
- {
- return q2 > q1;
- }
Add Comment
Please, Sign In to add comment