This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef QUICK_SORT_HPP | |
#define QUICK_SORT_HPP | |
#include <algorithm> | |
#include <random> | |
template<typename Iterator> | |
class QuickSort | |
{ | |
public: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef TRIE_HPP | |
#define TRIE_HPP | |
#include <array> | |
#include <cstddef> | |
#include <string> | |
template<typename Value, typename String = std::string, std::size_t N = 128> | |
class Trie | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename Node> | |
bool _is_palindrome(Node* left, Node*& right, bool& move_back) | |
{ | |
if (left != right) | |
{ | |
if (! _is_palindrome(left->next, right, move_back)) return false; | |
} | |
if (! move_back) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef LIST_GRAPH_HPP | |
#define LIST_GRAPH_HPP | |
#include <cstddef> | |
#include <queue> | |
#include <vector> | |
class ListGraph | |
{ | |
public: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MATRIX_GRAPH_HPP | |
#define MATRIX_GRAPH_HPP | |
#include <algorithm> | |
#include <array> | |
#include <bitset> | |
#include <cstddef> | |
#include <stdexcept> | |
template<std::size_t V> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool is_binary_palindrome(unsigned int value) | |
{ | |
unsigned int left = 1 << (sizeof(value) * 8 - 1); | |
while (!(value & left)) left >>= 1; | |
for (unsigned int right = 1; left > right; left >>= 1, right <<= 1) | |
{ | |
bool left_bit = value & left; | |
bool right_bit = value & right; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int largest_product_of_n(std::vector<int> values, std::size_t n) | |
{ | |
if (values.size() < n) | |
{ | |
throw std::invalid_argument("Sequence size must at least n!"); | |
} | |
std::sort(values.begin(), values.end()); | |
int positive_product = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MEDIAN_KEEPER_HPP | |
#define MEDIAN_KEEPER_HPP | |
#include <queue> | |
#include <vector> | |
template<typename T> | |
class MedianKeeper | |
{ | |
public: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename Accumulator, typename Divisor, std::size_t N> | |
class Average | |
{ | |
public: | |
template<typename... Args> | |
constexpr auto operator()(Args&&... args) | |
{ | |
return _average(Accumulator(), std::forward<Args>(args)...); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template< | |
typename Iterator, | |
typename Predicate, | |
typename Condition | |
> | |
Iterator lower_bound_if(Iterator begin, | |
Iterator end, | |
Predicate predicate, | |
Condition condition) | |
{ |