I am looking for a list type which implement the following feature (pseudocode):
list.init(5, 2, 6, 9);
list.add(1) // 2, 6, 9, 1
list.add(4) // 6, 9, 1, 4
list.add(8) // 9, 1, 4, 8
Add new element to fixed size list and pop the oldest one. I am sorry, I don´t know the name of this concept so I asking you, what the name could be. ;)
My implementation in C++ would be actually this:
std::deque<double> values(4);
void add(double value)
{
values.pop_front();
values.push_back(value);
}
Are there any better implementations than mine, maybe alltime fixed size?
std::array
(smallish collections that don't leave scope) orstd::vector
(everything else).