-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.cpp
36 lines (34 loc) · 941 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <fstream>
#include "../head/Quick.h"
using namespace std;
/**
* Reads in a sequence of strings from standard input; quicksorts them;
* and prints them to standard output in ascending order.
* Shuffles the array and then prints the strings again to
* standard output, but this time, using the select method.
*
* @param args the command-line arguments
*/
int main() {
ifstream file("./data/tiny.txt");
string tmp;
vector<string> vec;
while (file >> tmp) {
vec.push_back(tmp);
}
Quick::sort(vec);
for (auto a: vec)
cout << a << " ";
cout << endl;
// shuffle
shuffle(vec.begin(), vec.end(), g);
cout << "select kth large in array: " << endl;
for (auto a: vec)
cout << a << " ";
cout << endl;
for (int i = 0; i < vec.size(); ++i) {
auto str = Quick::select(vec, i);
cout << i << " th: " << str << endl;
}
}