📄 checkinsert.cpp
字号:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
#include "sortbench.h"
#include "sortall.h"
#include "prompt.h"
#include "tvector.h"
typedef SortWrapper<string> 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());
tvector<Wstring>list;
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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -