//File:	sort.cpp
#include <fstream>
#include <vector>

void read_in (ifstream & in, vector<int> & v);
void sort (vector<int> & v);
void write_out (ofstream & out, const vector<int> & v);
using namespace std;

int main()
{
	vector<int> v;

	ifstream fin ("integers.txt");
	ofstream fout ("out.txt");

	read_in (fin, v);
	
	for (int j=0; j<v.size(); j++)
		cout << v[j] <<  endl;
	cout << endl;

	sort (v);

	for (int k=0; k<v.size(); k++)
		cout << v[k] << endl;

	write_out (fout, v);

	return 0;
}

//Since vectors are NOT automatically passed by reference
//the & is necessary (& v)
void read_in (ifstream & in, vector<int> & v)
{
	int number;
	int n=0;	//LOCAL VARIABLE NOW
	while (in>>number)
	{
		v.resize(++n);	//Vectors allow dynamic sizing of the list!
		v[n-1]=number;
	}
}

void swap (int & a, int & b)
{
	int temp;

	temp = a;
	a	 = b;
	b	 = temp;
}

void sort (vector<int> & v)
{
	for (int i=v.size(); i>=2; i--)  // n = the number of items in the list
        for (int j=0; j<i-1; j++)
            if (v[j] > v[j+1])
               swap (v[j], v[j+1]);
}

void write_out (ofstream & out, const vector<int> & v)
{
	for (int k=0; k<v.size(); k++)
	{
		out << v[k] << endl;
	}
}
