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 T> | |
std::pair<bool, std::size_t> _tree_is_balanced(const TreeNode<T>* node) | |
{ | |
if (! node) return {true, 0}; | |
auto left = _tree_is_balanced(node->left); | |
if (! left.first) return {false, 0}; | |
auto right = _tree_is_balanced(node->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
template<typename Iterator, typename T> | |
bool find_with_empty(Iterator begin, Iterator end, const T& value) | |
{ | |
if (begin == end || value < *begin || value > *std::prev(end)) | |
{ | |
return false; | |
} | |
auto middle = begin; | |
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 Key, typename Value> | |
class OpenAddressingHashTable | |
{ | |
public: | |
using size_t = std::size_t; | |
using pre_hash_t = std::function<size_t(const Key&)>; | |
static const size_t minimum_capacity = 20; |
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 SEPARATE_CHAINING_HASH_TABLE_HPP | |
#define SEPARATE_CHAINING_HASH_TABLE_HPP | |
#include <algorithm> | |
#include <cmath> | |
#include <functional> | |
template<typename Key, typename Value> | |
class SeparateChainingHashTable | |
{ |
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 RED_BLACK_TREE_HPP | |
#define RED_BLACK_TREE_HPP | |
#include <assert.h> | |
#include <initializer_list> | |
#include <stdexcept> | |
template<typename Key, typename Value> | |
class RedBlackTree | |
{ |
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 MAX_HEAP_HPP | |
#define MAX_HEAP_HPP | |
#include <algorithm> | |
#include <cstddef> | |
#include <initializer_list> | |
#include <stdexcept> | |
template<typename T> | |
class MaxHeap |
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 HEAP_FILTER_HPP | |
#define HEAP_FILTER_HPP | |
#include <algorithm> | |
#include <cstddef> | |
#include <initializer_list> | |
#include <stdexcept> | |
template<typename T> | |
class HeapFilter |
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 MERGE_SORT_SINGLE_FUNCTION_HPP | |
#define MERGE_SORT_SINGLE_FUNCTION_HPP | |
#include <assert.h> | |
#include <algorithm> | |
#include <iterator> | |
#include <vector> | |
template<typename Iterator, | |
typename T = typename std::iterator_traits<Iterator>::value_type> |
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 MERGE_SORT_HPP | |
#define MERGE_SORT_HPP | |
#include <algorithm> | |
#include <iterator> | |
#include <vector> | |
template<typename Iterator> | |
class MergeSort | |
{ |
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_SINGLE_FUNCTION_HPP | |
#define QUICK_SORT_SINGLE_FUNCTION_HPP | |
#include <iterator> | |
#include <utility> | |
template<typename Iterator> | |
void quick_sort(Iterator begin, Iterator end) | |
{ | |
if (begin == end || std::next(begin) == end) return; |