-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubblesort_datafromfile.cpp
48 lines (42 loc) · 1.12 KB
/
bubblesort_datafromfile.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
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
#include <chrono>
using namespace std;
void print(const vector<string>& v) {
for (auto i : v)
cout << i << " ";
cout << "\n";
}
template<typename IteratorType>
void bsort(IteratorType first, IteratorType last) {
for (IteratorType jt = last; jt != first; --jt) {
for (IteratorType it = first; it < jt - 1; ++it) {
if (*it > *(it + 1)) {
iter_swap(it, it + 1);
}
}
}
}
int main() {
vector<string> v;
fstream in;
in.open("plik.txt", ios::in);
string input;
while (in >> input) {
v.push_back(input);
}
cout << "Before bubble sort: \n";
print(v);
auto t1 = chrono::high_resolution_clock::now();
bsort<vector<string>::iterator>(v.begin(), v.end());
auto t2 = chrono::high_resolution_clock::now();
auto dt = chrono::duration_cast<chrono::microseconds>(t2 - t1);
cout << "After bubble sort: \n";
print(v);
cout << "Bubble sort duration: " << dt.count() << " milisekund.\n";
in.close();
return 0;
}