I need a queue on n items where insertion of (n+1)th item removes the 0th item and insertion can only be made on the "back".
Is there any such structure already there in boost or standard library?
The queue. size() function in Java is used to get the current size of a queue. queue. size() returns the number of elements in the queue.
Fixed Size/Capacity Queue It is a queue, and the size of the queue is fixed, it means that the queue cannot hold more than specified limit of number of data.
A queue is a container that enables you to hold an unlimited number of items. Queue items can store multiple types of data, such as invoice information or customer details.
The capacity of a Queue is the number of elements the Queue can hold. As elements are added to a Queue, the capacity is automatically increased as required through reallocation.
You can use a boost::circular_buffer
wrapped by a std::queue
, something like this:
#include <queue>
#include <boost/circular_buffer.hpp>
typedef std::queue<my_type, boost::circular_buffer<my_type>> my_queue;
const int n = 3;
...
my_queue q(boost::circular_buffer<my_type>(n));
q.push(1);
q.push(2);
q.push(3);
q.push(4); // queue now contains 2,3,4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With