deques slowes program if if not used?
So I have this deque
deque <int> a[1001];
And a simply add elements by using
a[i].push_back(val);
And erase them using
a[i].pop_front();
If I use a[1001]
it works great, if I use a[10001]
it takes a few seconds and if I use a[100001]
it takes something like 30seconds to execute the program.
The thing is that in every case I only push_back like 5 vals, the only difference is the size of the deque.
Why's that?
I only need to erase elements from the front开发者_如何学C, is there a better way? :D
Oh and also, how many bytes does a push_backed element use?:D (in this type of deque)
deque<int> a[1001];
It's not a deque of size 1001, it's rather 1001 deques, each must be initialized and destructed, hence the slowness. You create a deque like this:
deque<int> a;
a.push_back(2);
a.push_back(3);
a.push_back(5);
a.push_back(7);
a.pop_back(); // ...
精彩评论