/*****************************************************************************
 * This is an illustration of list iterators. Note it is virtually a direct 
 * copy of the iteratorIntro.cpp program, except that 'vector' is replaced by
 * 'list' throughout. This illustrates the uniformity of iterator access.
 * ****************************************************************************/
#include <iostream>
#include <list>
#include<string>
using std::cin; using std::cout;            
using std::endl; using std::list;
using std::string;


void iter_show_lis(const list<int> & v);
int main()
{
	list<int> lis;
	int x;
	string garbage;
	cout<<" Please enter space-separated integers, "
		<<"then 's' to stop: ";
	while(cin>>x)
		lis.push_back(x);

	cin.clear();
	cin>>garbage;// Collect the 's'.
	cout<<"\nEnter an integer. The program will convert any\nof the "
		<<"original values that is greater than that integer to "
		<<"that value.\n";
		cin>>x;
	list<int>::iterator it=lis.begin();//This cannot be a const iterator
					     // because we plan to use it to 
					     // modify  lis.
	while(it!=lis.end())
	{
		if(*it>x)
			*it=x;
		++it;
	}
	cout<<"\nThe result is \n";
	iter_show_lis(lis);
	return 0;
			
}
void iter_show_lis(const list<int> & l)
{
	for(list<int>::const_iterator iter=l.begin(); iter!=l.end();++iter)
		cout<<*iter<<" ";
	/* We need a const iterator here because we passed l by constant 
	 * reference.
	 */   
	return;
}
	
