// Copyright 2005 Daniel Cer (daniel.cer@cs.colorado.edu) // // This work is licensed under the Creative Commons Attribution-NonCommercial- // ShareAlike License. To view a copy of this license, visit // http://creativecommons.org/licenses/by-nc-sa/2.5/ or send a letter to // Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, // 94105, USA. #include #include #include #include using namespace std; template void insertion_sort(vector &entries) { int entries_sz = entries.size(); for (int i = 1; i < entries_sz; i++) { int j; T value = entries[i]; for (j = i-1; j > -1; j--) { if (entries[j] <= value) break; entries[j+1] = entries[j]; } entries[j+1] = value; } } int main(int argc, char *argv[]) { if (argc != 2) { cerr<<"Usage:\n\t"< entries; // read in entries to sort for (float f; istrm>>f, istrm.good(); ) entries.push_back(f); istrm.close(); // sort them insertion_sort(entries); // display the results for (vector::iterator iter=entries.begin(); iter != entries.end(); iter++) cout<<*iter<