#include #include #include using namespace std; #include "sortbench.h" #include "sortall.h" #include "prompt.h" #include "tvector.h" typedef SortWrapper Wstring; struct ReverseComparer // for sorting in reverse alphabetical order { int compare(const Wstring& lhs, const Wstring& rhs) const { if (lhs < rhs) return +1; if (rhs < lhs) return -1; return 0; } }; int main() { string word, filename = PromptString("filename:"); ifstream input(filename.c_str()); tvectorlist; while (input >> word) { list.push_back(Wstring(word)); } cout << "# words read =\t " << list.size() << endl; Wstring::clear(); // clear push_back assigns InsertSort(list,list.size()); cout << "# compares\t = " << Wstring::compareCount() << endl; cout << "# assigns\t = " << Wstring::assignCount() << endl; Wstring::clear(); cout << endl << "sorting a sorted vector" << endl; InsertSort(list,list.size()); cout << "# compares\t = " << Wstring::compareCount() << endl; cout << "# assigns\t = " << Wstring::assignCount() << endl; InsertSort(list,list.size(),ReverseComparer()); Wstring::clear(); cout << endl << "sorting a reverse-sorted vector" << endl; InsertSort(list,list.size()); cout << "# compares\t = " << Wstring::compareCount() << endl; cout << "# assigns\t = " << Wstring::assignCount() << endl; return 0; }