// File: sort-driver.cc
// test template-ized bubble sort function

#include <iostream>
using namespace std;

template <class T >
void bubble_sort( T [],  int );

int main() {
   int x[5] = {5, 3, 4, 8, 2};

   float y[4] = {4.4, 5.5, 2.2, 1.1};

   bubble_sort( x, 5 );
   bubble_sort( y, 4 );

}

// Bubble sort - template version
template <class T>
void bubble_sort( T x[], const int n ) {
	int pass = 0, k, switches;
	T temp;

	switches = 1;

	while( switches ) {
	    switches = 0;
	    pass++;
	    for( k = 0; k < n - pass; k++ ) {
		if( x[k] > x[k+1] ) {
		    temp = x[k];
		    x[k] = x[k+1];
		    x[k+1] = temp;
		    switches = 1;
		}
	    }
	}

	return;
}
