/***************************************************************************
 * This program illustrates the generic function 'copy' with back_ and
 * front_inserter.
 ***************************************************************************/
#include <iostream>
#include <list>
#include<vector>
#include<string>

using std::cin;           
using std::cout;            
using std::endl;            
using std::list;
using std::vector;
using std::string;
using std::back_inserter; using std::copy;
using std::front_inserter;

typedef list<int> seq;/* This could be replaced with a vector, though
			 the lines concerning the front inserter would
			 have to be commented out.
			 */

void show_seq(const seq& s);



int main()
{

	seq custom, tail, header;
	int x, query;
	string stop_string;
	cout<<"\nPlease enter space-separated integers, and 's' to stop:";
	while(cin>>x)
		custom.push_back(x);//Load 'custom' from the keyboard.
	cin.clear();
	cin>>stop_string;// Pull in the end character and discard.
	cout<<"The sequence 'custom' contains\n";
	show_seq(custom);
	
	//Put sequences in 'tail' and 'header'.
	for(int i=0; i!=11; i++)
		tail.push_back(10*i);
	for(int j=0; j!=6; j++)
		header.push_back(j);
	
	/* 'copy' with a back_inserter act like a sequence of 'push_back's */
	copy(tail.begin(),tail.end(), back_inserter(custom));
	cout<<"\nWith the numbers 0-100 by 10's at the end, get \n";
	show_seq(custom);
	
	/* 'copy' with a front_inserter acts like a sequence of 'push_front's */
	copy(header.begin(),header.end(), front_inserter(custom));
	cout<<"\nNow count down from 5 at the beginning: \n";
	show_seq(custom);
	
			

	

	return 0;
	

	
}

void show_seq(const seq& s)
{
	for(seq::const_iterator iter=s.begin(); iter!=s.end();++iter)
		cout<<*iter<<" ";
	
	return;
}


