class MovingAverage {

public:

/** Initialize your data structure here. */

MovingAverage(int size) {

n = size;

sum = 0;

}

```
double next(int val) {
sum += val;
q.push_back(val);
if(q.size() > n) {
sum -= q.front();
q.pop_front();
}
return sum / double(q.size());
}
int n, sum;
deque<int> q;
```

};