Mar 28, 2012 at 3:40pm UTC
By using vector or a C++ array.
array<int ,4> array={1,2,3,4};
or
vector<int > array={1,2,3,4};
Mar 28, 2012 at 5:07pm UTC
do you mean i should store my arrays into a vector or another array? i cant really do that(not allowed to do that) i have to use queue's.
Mar 28, 2012 at 5:50pm UTC
No, you're supposed to store vectors or arrays in the queue.
Mar 28, 2012 at 6:03pm UTC
If what you are trying to do is to add the elements stored in the array to the queue you can use a loop.
1 2 3 4 5 6 7 8 9 10 11
#include <queue>
int main()
{
std::queue<int > myqueue;
int array[4] = {1,2,3,4};
for (int i = 0; i < 4; ++i)
{
myqueue.push(array[i]);
}
}
Or you could write a function to do it for you
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <queue>
template <int N>
void pushArray(std::queue<int >& myqueue, int (&array)[N])
{
for (int i = 0; i < N; ++i)
{
myqueue.push(array[i]);
}
}
int main()
{
std::queue<int > myqueue;
int array[4] = {1,2,3,4};
pushArray(myqueue, array);
}
Last edited on Mar 28, 2012 at 6:05pm UTC
Mar 28, 2012 at 7:43pm UTC
no i don't want to store individual elements of the array into the queue i know how to do that already and i think i get what your saying athar thanks.