#include #include #include using namespace std; void bubbleSort( vector & ); bool check(vector &list) { for(int a = 0; a < list.size() - 1; a++) if(list[a] > list[a + 1]) { cout << "Error: " << list[a] << " is greater than " << list[a + 1] << endl; return false; } return true; } template inline void Swap(T &a, T &b) { T temp = a; a = b; b = temp; } int main() { ifstream infile( "in1100.txt" ); clock_t t1, t2; int number = 0; vector list; while( infile >> number ) { list.push_back( number ); } infile.close(); t1 = clock(); bubbleSort( list ); t2 = clock(); if(check(list)) cout << "Checked out OKAY.\n\n"; else cout << "There were errors...\n\n"; cout << "\nTIME: " << (t2-t1) / (float)CLOCKS_PER_SEC << endl; system("PAUSE"); return 0; } void bubbleSort(vector &array) { int temp; bool swap = false; for(int a = 0; a < array.size(); a++) { swap = false; for(int b = array.size() - 1; b > a; b--) { if(array[b - 1] > array[b]) { Swap(array[b],array[b-1]); swap = true; } } if(!swap) break; } }