finish ex02
This commit is contained in:
parent
45c341d78d
commit
0b0bd6d513
@ -56,7 +56,7 @@ void insert_sort(const std::pair<int, int>* pairs, size_t len, T& array)
|
|||||||
array.push_back(pairs[i].first);
|
array.push_back(pairs[i].first);
|
||||||
if (pairs[i].first == pairs[i].second)
|
if (pairs[i].first == pairs[i].second)
|
||||||
continue;
|
continue;
|
||||||
ssize_t index = binary_search(array, 0, array.size() - 1, pairs[i].second);
|
size_t index = binary_search(array, 0, array.size() - 1, pairs[i].second);
|
||||||
array.insert(array.begin() + index, pairs[i].second);
|
array.insert(array.begin() + index, pairs[i].second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,67 @@
|
|||||||
#include "PmergeMe.hpp"
|
#include "PmergeMe.hpp"
|
||||||
|
#include <cctype>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <time.h>
|
||||||
|
#include <deque>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void display(const T& array)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i != array.size(); i++)
|
||||||
|
std::cout << array[i] << " ";
|
||||||
|
}
|
||||||
|
|
||||||
int main(int ac, char** av)
|
int main(int ac, char** av)
|
||||||
{
|
{
|
||||||
std::vector<int> input(ac - 1);
|
|
||||||
std::cout << "Before: ";
|
|
||||||
for (int i = 1; i != ac; i++)
|
|
||||||
{
|
{
|
||||||
input[i - 1] = atoi(av[i]);
|
std::vector<int> array(ac - 1);
|
||||||
std::cout << av[i] << " ";
|
|
||||||
|
for (int i = 1; i != ac; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; av[i][j] != '\0'; j++)
|
||||||
|
{
|
||||||
|
if (!std::isdigit(av[i][j]))
|
||||||
|
{
|
||||||
|
std::cout << "Error" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
array[i - 1] = atoi(av[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Before: ";
|
||||||
|
display(array);
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
const clock_t time_vec_start = clock();
|
||||||
|
|
||||||
|
PmergeMe(array);
|
||||||
|
|
||||||
|
const clock_t time_vec_stop = clock();
|
||||||
|
|
||||||
|
std::cout << "After: ";
|
||||||
|
display(array);
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << "Time to process a range of " << array.size() <<" elements with std::vector : " << ((double) (time_vec_stop - time_vec_start) / CLOCKS_PER_SEC) * 1000000 << " us" << std::endl;
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
|
||||||
PmergeMe(input);
|
|
||||||
std::cout << "After: ";
|
|
||||||
for (size_t i = 0; i != input.size(); i++)
|
|
||||||
{
|
{
|
||||||
std::cout << input[i] << " ";
|
std::deque<int> array(ac - 1);
|
||||||
|
for (int i = 1; i != ac; i++)
|
||||||
|
array[i - 1] = atoi(av[i]);
|
||||||
|
|
||||||
|
std::cout << "Before: ";
|
||||||
|
display(array);
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
const clock_t time_deque_start = clock();
|
||||||
|
|
||||||
|
PmergeMe(array);
|
||||||
|
|
||||||
|
const clock_t time_deque_stop = clock();
|
||||||
|
|
||||||
|
std::cout << "Time to process a range of " << array.size() <<" elements with std::vector : " << ((double) (time_deque_stop - time_deque_start) / CLOCKS_PER_SEC) * 1000000 << " us" << std::endl;
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user