How do i store arrays in a queue?

can some body please give an example of how to store entire arrays of integers into queue's?
1
2
3
4
5
queue<int>myqueue;
int array[4]=[1,2,3,4]
int p[2]=[1,2]
myqueue.push(array[])
myqueue.push(p[])


is something that i tried but did not work. not sure if you can even do this.

thanks in advance.
By using vector or a C++ array.
array<int,4> array={1,2,3,4};

or

vector<int> array={1,2,3,4};
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.
No, you're supposed to store vectors or arrays in the queue.
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
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.
Topic archived. No new replies allowed.