#include <iostream.h>

template <class Item>
void sort(Item array[], int n);

void main()
{
  int n = 7;
  int i = 0;
  double dfArray[] = {3.1, 5.9, 2.9, 8.5, 7.6, 1.1, 3.3};
  int iArray[] = {3, 5, 2, 8, 7, 1, 3};
  char cArray[] = {'z', 'y', 'x', 'p', 'r', 'a', 'n'};


  cout << "Unsorted array: ";
  for (i = 0; i < n; i++)
  {
    cout << dfArray[i] << " ";
  }
  cout << endl;

  sort(dfArray, n);

  cout << "Sorted array:   ";
  for (i = 0; i < n; i++)
  {
    cout << dfArray[i] << " ";
  }
  cout << endl << endl;

  cout << "Unsorted array: ";
  for (i = 0; i < n; i++)
  {
    cout << iArray[i] << " ";
  }
  cout << endl;

  sort(iArray, n);

  cout << "Sorted array:   ";
  for (i = 0; i < n; i++)
  {
    cout << iArray[i] << " ";
  }
  cout << endl << endl;

  cout << "Unsorted array: ";
  for (i = 0; i < n; i++)
  {
    cout << cArray[i] << " ";
  }
  cout << endl;

  sort(cArray, n);

  cout << "Sorted array:   ";
  for (i = 0; i < n; i++)
  {
    cout << cArray[i] << " ";
  }
  cout << endl << endl;

}

template <class Item>
void sort(Item array[], int n)
{
  int i = 0;
  int j = 0;

  Item swapTemp = 0;

  for (i = 1; i < n; i++)
  {
    for (j = 0; j < i; j++)
    {
      if (array[i] < array[j])
      {
        swapTemp = array[i];
        array[i] = array[j];
        array[j] = swapTemp;
      }
    }
  }
}
