-
Notifications
You must be signed in to change notification settings - Fork 1
/
Queue.h
53 lines (45 loc) · 1.03 KB
/
Queue.h
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
template <int S>
class Queue
{
private:
float values[S] = {0};
int current = 0;
int actualSize = 0; // Number of added values. Cannot be grater that S
public:
void add(float value);
float average();
float min();
float max();
};
template <int S>
void Queue<S>::add(float value){
this->values[this->current] = value;
this->current ++;
if(this->current == S)
this->current = 0;
this->actualSize = ::min(this->actualSize + 1, S);
}
template <int S>
float Queue<S>::average(){
float sum = 0;
for(int i = 0; i < this->actualSize; i++){
sum += this->values[i];
}
return sum / this->actualSize;
}
template <int S>
float Queue<S>::min(){
float res = this->values[0];
for(float v: this->values){
res = ::min(res, v);
}
return res;
}
template <int S>
float Queue<S>::max(){
float res = this->values[0];
for(float v: this->values){
res = ::max(res, v);
}
return res;
}