forked from ssine/airport-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.cpp
More file actions
68 lines (56 loc) · 1.23 KB
/
Copy pathqueue.cpp
File metadata and controls
68 lines (56 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "stdafx.h"
#include <iostream>
#include <string>
#include <random>
#include <ctime>
#include <algorithm>
#include "queue.h"
#include "struct.h"
#include "passenger.h"
#include "globalvar.h"
using namespace std;
int maxVecNum = 500;
Queue::Queue() {
front = rear = num = 0;
for(int i = 0; i < maxVecNum; i++)
q.push_back(Passenger());
}
Passenger& Queue::operator[](int n) {
int index = (front + n) % maxVecNum;
return q[index];
}
void Queue::addPassenger(Passenger pass) {
q[rear] = pass;
rear = (rear + 1) % maxVecNum;
num++;
}
void Queue::addPassenger(int arriveTime, int checkTime) {
if (isoffDuty)
return;
Passenger pass(arriveTime, checkTime);
srand((unsigned)time(NULL));
if(rand()%100<6)
pass.isMuslim = true;
else
pass.isMuslim = false;
q[rear] = pass;
rear = (rear + 1) % maxVecNum;
num++;
}
void Queue::popPassenger() {
front = (front + 1) % maxVecNum;
num--;
}
Passenger& Queue::getFirstPassenger() {
return q[front];
}
Passenger& Queue::getLastPassenger() {
return q[(rear+499)%maxVecNum];
}
int Queue::getNum() {
return num;
}
bool Queue::isempty()
{
return num == 0;
}