/SortAlgorithmCollection

Primary LanguageC++Boost Software License 1.0BSL-1.0

Sorting Algorithm Collection by C++

Build status

実装中…

Implemented algorithms.

  • bubble sort
  • shaker sort
  • comb sort
  • gnome sort
  • selection sort
  • insertion sort
  • shell sort
  • marge sort

Need for C++17 compiler. For exmaple:

  • Visual Studio 2017 15.9.4 or later
  • clang 7.0.0 or later
  • gcc 8.2.0 or later

sample code.

//header only.
#include "sort.hpp"

void sample_sort() {
  int array[] = {8, 1, 3, 2, 4, 6, 5, 7};
  
  //sorted by bubble sort.
  sort_collection::sort<sort_collection::bubble_sort>(array);
  
  for (auto& n : array) {
    std::cout << n << ", ";
  }
  //1, 2, 3, 4, 5, 6, 7, 8, 
}

void sample_sort2() {
  int array[] = {8, 1, 3, 2, 4, 6, 5, 7};
  
  //create functor for sort.
  constexpr sort_collection::shaker_sort shaker_sort{};
  
  //sorted by shaker sort.
  shaker_sort(std::begin(array), std::end(array), std::less<int>{});
  
  for (auto& n : array) {
    std::cout << n << ", ";
  }
  //1, 2, 3, 4, 5, 6, 7, 8, 
}

Run the sample code in Wandbox.