add: parsing check values

This commit is contained in:
starnakin 2023-12-13 18:17:59 +01:00
parent 0b0bd6d513
commit b7beda1ebe
2 changed files with 25 additions and 9 deletions

View File

@ -64,6 +64,8 @@ void insert_sort(const std::pair<int, int>* pairs, size_t len, T& array)
template <typename T>
void PmergeMe(T& array)
{
if (array.size() < 2)
return;
std::size_t len = array.size() / 2 + array.size() % 2;
std::pair<int, int>* pairs = create_pairs(array, len);
sort_pair(pairs, len);

View File

@ -1,4 +1,5 @@
#include "PmergeMe.hpp"
#include <algorithm>
#include <cctype>
#include <cstddef>
#include <cstdlib>
@ -17,20 +18,23 @@ void display(const T& array)
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 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;
return 1;
}
}
array[i - 1] = atoi(av[i]);
}
if (array.size() > 0)
array.pop_back();
std::cout << "Before: ";
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::deque<int> array(ac - 1);
for (int i = 1; i != ac; i++)
array[i - 1] = atoi(av[i]);
std::deque<int> array;
std::cout << "Before: ";
display(array);
std::cout << std::endl;
for (int i = 1; i != ac; i++)
{
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();