class MovingAverage {
private:
int n=0;
int sum=0;
queue<int>q;
public:
/** Initialize your data structure here. */
MovingAverage(int size) {
n=size;
}
double next(int val) {
if(q.size()==n)
{
int t=q.front();
q.pop();
q.push(val);
sum=sum-t+val;
}
else
{
q.push(val);
sum+=val;
}
return sum*1.0/min(n,int(q.size()));
}
};
/**
* Your MovingAverage object will be instantiated and called as such:
* MovingAverage* obj = new MovingAverage(size);
* double param_1 = obj->next(val);
*/