This commit is contained in:
starnakin 2023-12-13 13:09:28 +01:00
parent f2fb5bf00b
commit 27534a8198
3 changed files with 15 additions and 13 deletions

View File

@ -1,6 +1,4 @@
#include "./PmergeMe.hpp" #include "./PmergeMe.hpp"
#include <future>
#include <utility>
void sort_pair(std::pair<int, int>* pairs, size_t len) void sort_pair(std::pair<int, int>* pairs, size_t len)
{ {
@ -17,7 +15,7 @@ void sort_pairs(std::pair<int, int>* pairs, size_t len)
return; return;
size_t count = 0; size_t count = 0;
for (size_t i = 0; i < len; i++) for (size_t i = 0; i < len - 1; i++)
{ {
if (pairs[i].first > pairs[i + 1].first) if (pairs[i].first > pairs[i + 1].first)
{ {
@ -29,5 +27,5 @@ void sort_pairs(std::pair<int, int>* pairs, size_t len)
if (count == 0) if (count == 0)
return; return;
sort_pair(pairs, len - 1); sort_pairs(pairs, len - 1);
} }

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <cstddef> #include <cstddef>
#include <future>
#include <iostream> #include <iostream>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -16,13 +15,11 @@ std::pair<int, int>* create_pairs(const T& array, size_t len)
for (size_t i = 0; i != len; i++) for (size_t i = 0; i != len; i++)
{ {
if (i % 2) pairs[i].second = array[i * 2];
pairs[i].second = array[i]; pairs[i].first = array[i * 2 + 1];
else
pairs[i].first = array[i];
} }
if (len > 0 && len % 2) if (len % 2)
pairs[len - 1].second = pairs[len - 1].first; pairs[len - 1].first = pairs[len - 1].second;
return pairs; return pairs;
} }

View File

@ -5,13 +5,20 @@
int main(int ac, char** av) int main(int ac, char** av)
{ {
std::vector<int> input(ac); std::vector<int> input(ac - 1);
std::cout << "Before: "; std::cout << "Before: ";
for (int i = 1; i != ac; i++) for (int i = 1; i != ac; i++)
{ {
input.push_back(atoi(av[i])); input[i - 1] = atoi(av[i]);
std::cout << av[i] << " "; std::cout << av[i] << " ";
} }
std::cout << std::endl; std::cout << std::endl;
PmergeMe(input); PmergeMe(input);
std::cout << "After: ";
for (int i = 1; i != ac; i++)
{
input[i - 1] = atoi(av[i]);
std::cout << av[i] << " ";
}
std::cout << std::endl;
} }