// COMS 2203 02
// Lab #1 

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

const int N = 100; // array size (max number of items that can be stored)

void sort(int a[], int n)
{
    for(int i = 0; i < n - 1; ++i)
    for(int j = n - 1; j > i; --j)
    if(a[j] < a[j - 1]) {
          int temp = a[j];
          a[j] = a[j - 1];
          a[j - 1] = temp;
                           }
}

int main()
{
  ifstream infile;
  string fname;
  int x;     // item from file
  int k;     // number of items stored in array, array subscript (index)
  int a[N];  // array 

  cout << "File name? ";
  cin >> fname;
  infile.open(fname.c_str());
  if(!infile) {
    cerr << "Error: Can't open file." << endl;
    return 1;
  } 
  
  k = 0;         // initialize array subscript value
  infile >> x;   // read 1st item
  while(infile && k < N) { // if not eof and array has space for item
    a[k] = x;    // store item in array              
    ++k;         // next location in array, number of items in array
    infile >> x; // read next item              
  }

  sort(a, k);
  
  for(int i = 0; i < k; ++i)
    cout << a[i] << endl;
  return 0;
}

