add insertion sort
This commit is contained in:
24
bin/main.cpp
24
bin/main.cpp
@@ -1,19 +1,27 @@
|
|||||||
#include <hack/logger/logger.hpp>
|
#include <hack/logger/logger.hpp>
|
||||||
|
|
||||||
|
#include "base/insertion_sort.hpp"
|
||||||
|
|
||||||
#include "numbers/gcd.hpp"
|
#include "numbers/gcd.hpp"
|
||||||
#include "numbers/prime_factors.hpp"
|
#include "numbers/prime_factors.hpp"
|
||||||
|
|
||||||
auto main() -> int
|
auto main() -> int
|
||||||
{
|
{
|
||||||
hack::log()(algorithms::gcd(4851, 3003));
|
|
||||||
hack::log()(algorithms::gcd(64, 28));
|
|
||||||
|
|
||||||
hack::log()(algorithms::prime_factors_v1(127));
|
// std::vector<int> v { 2, 5, 4, 6, 1, 3 };
|
||||||
hack::log()(algorithms::prime_factors_v1(128));
|
std::vector<int> v { 5, 4, 1, 5, 6 };
|
||||||
hack::log()(algorithms::prime_factors_v1(130));
|
algorithms::insertion_sort(v);
|
||||||
|
hack::log()(v);
|
||||||
|
|
||||||
hack::log()(algorithms::prime_factors_v2(127));
|
// hack::log()(algorithms::gcd(4851, 3003));
|
||||||
hack::log()(algorithms::prime_factors_v2(128));
|
// hack::log()(algorithms::gcd(64, 28));
|
||||||
hack::log()(algorithms::prime_factors_v2(130));
|
//
|
||||||
|
// hack::log()(algorithms::prime_factors_v1(127));
|
||||||
|
// hack::log()(algorithms::prime_factors_v1(128));
|
||||||
|
// hack::log()(algorithms::prime_factors_v1(130));
|
||||||
|
//
|
||||||
|
// hack::log()(algorithms::prime_factors_v2(127));
|
||||||
|
// hack::log()(algorithms::prime_factors_v2(128));
|
||||||
|
// hack::log()(algorithms::prime_factors_v2(130));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
25
src/base/insertion_sort.hpp
Normal file
25
src/base/insertion_sort.hpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <hack/logger/logger.hpp>
|
||||||
|
|
||||||
|
// Сортировка вставкой
|
||||||
|
namespace algorithms
|
||||||
|
{
|
||||||
|
inline void insertion_sort(std::vector<int>& v)
|
||||||
|
{
|
||||||
|
for (std::size_t i = 1; i < v.size(); ++i)
|
||||||
|
{
|
||||||
|
auto key = v[i];
|
||||||
|
auto j = i;
|
||||||
|
|
||||||
|
while (j > 0 && v[j - 1] > key)
|
||||||
|
{
|
||||||
|
v[j] = v[j - 1];
|
||||||
|
--j;
|
||||||
|
}
|
||||||
|
v[j] = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
inc += include_directories('.')
|
inc += include_directories('.')
|
||||||
|
|
||||||
headers = [
|
headers = [
|
||||||
|
'base/insertion_sort.hpp',
|
||||||
'numbers/gcd.hpp',
|
'numbers/gcd.hpp',
|
||||||
'numbers/prime_factors.hpp'
|
'numbers/prime_factors.hpp'
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user