add: parsing check values
This commit is contained in:
parent
0b0bd6d513
commit
b7beda1ebe
@ -64,6 +64,8 @@ void insert_sort(const std::pair<int, int>* pairs, size_t len, T& array)
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
void PmergeMe(T& array)
|
void PmergeMe(T& array)
|
||||||
{
|
{
|
||||||
|
if (array.size() < 2)
|
||||||
|
return;
|
||||||
std::size_t len = array.size() / 2 + array.size() % 2;
|
std::size_t len = array.size() / 2 + array.size() % 2;
|
||||||
std::pair<int, int>* pairs = create_pairs(array, len);
|
std::pair<int, int>* pairs = create_pairs(array, len);
|
||||||
sort_pair(pairs, len);
|
sort_pair(pairs, len);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "PmergeMe.hpp"
|
#include "PmergeMe.hpp"
|
||||||
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@ -17,20 +18,23 @@ void display(const T& array)
|
|||||||
int main(int ac, char** av)
|
int main(int ac, char** av)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::vector<int> array(ac - 1);
|
std::vector<int> array;
|
||||||
|
|
||||||
for (int i = 1; i != ac; i++)
|
for (int i = 1; i != ac; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; av[i][j] != '\0'; j++)
|
for (int j = 0; av[i][j] != '\0'; j++)
|
||||||
{
|
{
|
||||||
if (!std::isdigit(av[i][j]))
|
if (j == 0 || av[i][j] == ' ')
|
||||||
|
array.push_back(atoi(av[i] + j + (j != 0)));
|
||||||
|
if (!std::isdigit(av[i][j]) and av[i][j] != ' ')
|
||||||
{
|
{
|
||||||
std::cout << "Error" << std::endl;
|
std::cout << "Error" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
array[i - 1] = atoi(av[i]);
|
|
||||||
}
|
}
|
||||||
|
if (array.size() > 0)
|
||||||
|
array.pop_back();
|
||||||
|
|
||||||
std::cout << "Before: ";
|
std::cout << "Before: ";
|
||||||
display(array);
|
display(array);
|
||||||
@ -48,13 +52,23 @@ int main(int ac, char** av)
|
|||||||
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 << "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::deque<int> array(ac - 1);
|
std::deque<int> array;
|
||||||
for (int i = 1; i != ac; i++)
|
|
||||||
array[i - 1] = atoi(av[i]);
|
|
||||||
|
|
||||||
std::cout << "Before: ";
|
for (int i = 1; i != ac; i++)
|
||||||
display(array);
|
{
|
||||||
std::cout << std::endl;
|
for (int j = 0; av[i][j] != '\0'; j++)
|
||||||
|
{
|
||||||
|
if (j == 0 || av[i][j] == ' ')
|
||||||
|
array.push_back(atoi(av[i] + j + (j != 0)));
|
||||||
|
else if (!std::isdigit(av[i][j]))
|
||||||
|
{
|
||||||
|
std::cout << "Error" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (array.size() > 0)
|
||||||
|
array.pop_back();
|
||||||
|
|
||||||
const clock_t time_deque_start = clock();
|
const clock_t time_deque_start = clock();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user