-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlowQueue.hpp
More file actions
42 lines (39 loc) · 932 Bytes
/
FlowQueue.hpp
File metadata and controls
42 lines (39 loc) · 932 Bytes
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
#ifndef FLOWQUEUE_HPP
#define FLOWQUEUE_HPP
struct FlowNode {
int time; // 第几分钟 (1-30)
int count; // 预测人数
FlowNode* next;
FlowNode(int t, int c) : time(t), count(c), next(nullptr) {}
};
class FlowQueue {
public:
FlowNode *front, *rear;
FlowQueue() : front(nullptr), rear(nullptr) {}
// 入队
void push(int t, int c) {
FlowNode* node = new FlowNode(t, c);
if (rear) rear->next = node;
else front = node;
rear = node;
}
// 查指定时间的人数
int get_count(int t) {
FlowNode* p = front;
while (p) {
if (p->time == t) return p->count;
p = p->next;
}
return 0; // 没找到
}
// 清空
void clear() {
while (front) {
FlowNode* t = front;
front = front->next;
delete t;
}
rear = nullptr;
}
};
#endif