Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<chrono>
- #include<random>
- using namespace std;
- size_t partition_j(vector<unsigned>& a, size_t lo, size_t hi);
- size_t partition_w(vector<unsigned>& a, size_t lo, size_t hi);
- size_t partition_k(vector<unsigned>& a, size_t lo, size_t hi);
- int main(int argc, char* argv[])
- {
- // Check if an argument was passed
- if (argc != 2)
- {
- cerr << "Usage: " << argv[0] <<
- " n where n is the number of values" << endl;
- return 1;
- }
- // Create a random number generator
- size_t number_of_values {static_cast<size_t>(stoul(argv[1]))};
- const unsigned MAX_RANDOM_VALUE = 1000000;
- default_random_engine get_next_value
- (static_cast <unsigned>
- (chrono::system_clock::now().time_since_epoch().count()));
- uniform_int_distribution<unsigned> uniform(0, MAX_RANDOM_VALUE);
- // Create two indentical vectors of size n
- vector<unsigned> v1;
- vector<unsigned> v2;
- vector<unsigned> v3;
- for(size_t i = 0; i < number_of_values; i++)
- {
- unsigned random_value = uniform(get_next_value);
- v1.push_back(random_value);
- v2.push_back(random_value);
- v3.push_back(random_value);
- }
- // Run all versions and print how many operations the did
- cout << number_of_values << " ";
- size_t dummy1 = partition_j(v1, 0, static_cast<size_t>(number_of_values - 1));
- cout << " ";
- size_t dummy2 = partition_w(v2, 0, static_cast<size_t>(number_of_values - 1));
- cout << " ";
- size_t dummy3 = partition_k(v3, 0, static_cast<size_t>(number_of_values - 1));
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement