Creating and implementing Deque functions

I'm writing 2 functions involving deque. The first is to fill a deque with 6 integers alternating what gets added to the front and back.
The second is a function to display the contents of the deque using an iterator, which I thought I had right, as I'm not getting errors, but it isn't printing anything in the deque. Suggestions?

1
2
3
#include <iostream>
#include <deque>
using namespace std;


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
void Fill(deque<int> d)
{
	cout<<"2a. Fill() adds 6 integers alternately to the front and back of a deque"<<endl; 
	for(int i = 0; i<6; i++)
	{
	int a;
	cout<<"Enter number: "<<endl;
	cin>>a;
	
	if(i%2==0||i==0)
		d.push_front(a);
	else
		d.push_back(a);
	
	}
};

void DisplayDeque(deque<int> d)
{
	deque<int>::iterator it = d.begin();
	cout<<"Current contents of deque<int> d: ";
	while(it!=d.end())
	{
		cout<<*it<<" ";
		it++;
	}
	cout<<endl;
};


1
2
3
4
5
6
7
int main()
{
	deque<int> deq;
	Fill(deq);
	DisplayDeque(deq);
return 0;
}
Last edited on
You need to pass your deque by reference
So simple. But I am so terrible at programming. Thank you!
Topic archived. No new replies allowed.