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 <future>
#include <utility>
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;
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)
{
@ -29,5 +27,5 @@ void sort_pairs(std::pair<int, int>* pairs, size_t len)
if (count == 0)
return;
sort_pair(pairs, len - 1);
sort_pairs(pairs, len - 1);
}

View File

@ -1,7 +1,6 @@
#pragma once
#include <cstddef>
#include <future>
#include <iostream>
#include <utility>
#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++)
{
if (i % 2)
pairs[i].second = array[i];
else
pairs[i].first = array[i];
pairs[i].second = array[i * 2];
pairs[i].first = array[i * 2 + 1];
}
if (len > 0 && len % 2)
pairs[len - 1].second = pairs[len - 1].first;
if (len % 2)
pairs[len - 1].first = pairs[len - 1].second;
return pairs;
}

View File

@ -5,13 +5,20 @@
int main(int ac, char** av)
{
std::vector<int> input(ac);
std::vector<int> input(ac - 1);
std::cout << "Before: ";
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 << std::endl;
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;
}