/* This code is designed to sort text only, and only text in upper case letters. */ #include #include #include #include #include using namespace std; typedef list stringlist; // will only work on upper case letters void bucketSort(vector & words, int pos) { int i; int j; int index; list::iterator k; vector buckets (27); // bin 26 is reserved for strings shorter than the current length // push all of the words into the right bins for(i=0;iwords; // the list to sort int i,j; ifstream infile; string tmp; int longest; // the length of the longest string infile.open("data"); // read in the data longest = 0; infile >> tmp; while(infile) { // keep track of the length of the longest string if (tmp.size() > longest) { longest = tmp.size(); } //insert the word into the list words.push_back(tmp); infile >> tmp; } infile.close(); // the radix sort for(j=longest-1;j>=0;j--) { // call to bucket sort bucketSort(words,j); // print the list so far cout << "Sorting on position " << j << endl; for(i=0;i