suitable data struct needed

hey guys. im implementing a program. and i need a data structure (like queue) which should has these features;
for example user inputs an integer => x;
I have to create something like an array => array[100][m]

this is easy but i will have to shift all the elements to the next row before add a new element.

lets say:
1
2
3
4
m=3;
arr[0][0]=0;
arr[0][1]=0;
arr[0][2]=0;


then im gonna add a new serie, lets say 1,2,3. then my array should be like this:

1
2
3
4
5
6
arr[0][0]=1;
arr[0][1]=2;
arr[0][2]=3;
arr[1][0]=0;
arr[1][1]=0;
arr[1][2]=0;

(like shifting)
and the last elements of array should be deleted. i mean
arr[100][0..m]=arr[99][0..m]

- If I use array, I have to run 2 for loops for shifting before adding (this is a huge problem for me and lots of time wasting)
- If I use queue, I dont know how to use it dynamically and multidimensonally...


Because the most important about my array/queue MUST be a global struct.

I tried to explain my problem as soon as I can.
Sorry for my bad english. I hope you guys understand what i want.. Any advice?
#include <boost/circular_buffer.hpp>

is this a standard library?
sadly, no it is not.

edit:

What I would do is define a struct containing an array of two deques. I'd define a function for pushing values onto the struct that would make use of deque::swap1 to shift values into the next row.



Last edited on
thanks buddy but in ur example, i think we cant define deques as global? I mean can we define before the main like " deque<int> first reserve" or sth like that? then allocate?
You can define any datatype as global.

If you can't use anything outside the STL then you could implement your own circular buffer. This is a pretty easy container to implement.
Topic archived. No new replies allowed.