binary_search_tree 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 namespace CLRS { // recursive version of search template <typename T> TreeNode<T> *tree_search(TreeNode<T> *x, T k) { if(x == nullptr || k == x->get_value()) return x; if(k < x->get_value()) return tree_search(x->get_left(), k); else return tree_search(x->get_right(), k); } // iterative version of serach template <typename T> TreeNode<T> *iterative_tree_search(TreeNode<T> *x, T k) { while(x !
CLRS-Cpp-Implementations-Chapter-11
hash_table_chaining 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 #include "chapter-10/list/list.h"namespace CLRS { template <typename T, std::size_t m, std::size_t m_d, std::size_t p_m> classHashTableChaining; template <typename T, std::size_t m, std::size_t m_d, std::size_t p_m> void chained_hash_insert(HashTableChaining<T, m, m_d, p_m> &, ListNode<T> &); template <typename T, std::size_t m, std::size_t m_d, std::size_t p_m> ListNode<T> *chained_hash_search(HashTableChaining<T, m, m_d, p_m> &, T); template <typename T, std::size_t m, std::size_t m_d, std::size_t p_m> void chained_hash_delete(HashTableChaining<T, m, m_d, p_m> &, ListNode<T> &); template <typename T, std::size_t m, std::size_t m_d, std::size_t p_m> classHashTableChaining { List<T> array[m]; public: List<T> &operator[](std::size_t i) {return array[i];} /* template needs explicitly instanced * with template non-type parameter m, * m is a prime number which is not close * to any power of 2.
CLRS-Cpp-Implementations-Chapter-10
stack 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 namespace CLRS { template <typename T, std::size_t n> classStack; template <typename T, std::size_t n> bool stack_empty(const Stack<T, n> &s) { if(!s.top) return true; else return false; } template <typename T, std::size_t n> void push(Stack<T, n> &s, T x) { std::size_t l = s.
CLRS-Cpp-Implementations-Chapter-8
bucket_sort 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 namespace CLRS { /* * Suppose elements of array uniformly and individually * scattered in half open interval [0, 1) * TODO: this time uses standard library list and iterator, * this program would be refactored after list implementation.
CLRS-Cpp-Implementations-Chapter-9
select 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 #include "chapter-2/insertion_sort/insertion_sort.