?? sortedsearchtest.cpp
字號:
//: C05:SortedSearchTest.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
//{L} ../C04/StreamTokenizer
// Test searching in sorted ranges
#include "../C04/StreamTokenizer.h"
#include "PrintSequence.h"
#include "NString.h"
#include "../require.h"
#include <algorithm>
#include <fstream>
#include <queue>
#include <vector>
using namespace std;
int main() {
ifstream in("SortedSearchTest.cpp");
assure(in, "SortedSearchTest.cpp");
StreamTokenizer words(in);
deque<NString> dstr;
string word;
while((word = words.next()).size() != 0)
dstr.push_back(NString(word));
vector<NString> v(dstr.begin(), dstr.end());
sort(v.begin(), v.end());
print(v, "sorted");
typedef vector<NString>::iterator sit;
sit it, it2;
string f("include");
cout << "binary search: "
<< binary_search(v.begin(), v.end(), f)
<< endl;
it = lower_bound(v.begin(), v.end(), f);
it2 = upper_bound(v.begin(), v.end(), f);
print(it, it2, "found range");
pair<sit, sit> ip =
equal_range(v.begin(), v.end(), f);
print(ip.first, ip.second,
"equal_range");
} ///:~
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -