Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <algorithm>
- #include <chrono>
- void sort_file(const std::string& input_path, const std::string& output_path) {
- std::ifstream input_file(input_path);
- std::ofstream output_file(output_path);
- std::vector<char> contents((std::istreambuf_iterator<char>(input_file)),
- std::istreambuf_iterator<char>());
- auto partition_point = std::partition(contents.begin(), contents.end(), [](char c) { return c != ' '; });
- std::sort(contents.begin(), partition_point);
- std::copy(contents.begin(), contents.end(), std::ostreambuf_iterator<char>(output_file));
- }
- int main() {
- auto start = std::chrono::high_resolution_clock::now();
- sort_file("input.txt", "output.txt");
- auto stop = std::chrono::high_resolution_clock::now();
- std::chrono::duration<double> elapsed = stop - start;
- std::cout << "RunTime: " << elapsed.count() << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment