Loading docs/ds/llrbt.md +11 −10 Original line number Diff line number Diff line Loading @@ -76,18 +76,19 @@ } ``` template<class Key, class Compare> typename Set<Key, Compare>::Node * Set<Key, Compare>::insert(Set::Node *root, const Key &key) const { if (root == nullptr) template<class Key, class Compare> typename Set<Key, Compare>::Node_Set<Key, Compare>::insert(Set::Node_root, const Key &key) const {if (root == nullptr) return new Node(key, kRed, 1); if (root->key == key); else if (cmp_(key, root->key)) // if (key < root->key) else if (cmp\_(key, root->key))//if (key < root->key) root->lc = insert(root->lc, key); else root->rc = insert(root->rc, key); return fix_up(root); } ``` ``` ### 删除 Loading Loading @@ -131,8 +132,8 @@ return root; } template <class Key, class Compare> typename Set<Key, Compare>::Node * Set<Key, Compare>::delete_min(Set::Node *root) const { typename Set<Key, Compare>::Node *Set<Key, Compare>::delete_min( Set::Node *root) const { if (root->lc == nullptr) { delete root; return nullptr; Loading @@ -145,7 +146,6 @@ root->lc = delete_min(root->lc); return fix_up(root); } ``` #### 删除任意节点 Loading Loading @@ -203,6 +203,7 @@ template <class Key, class Compare = std::less<Key>> class Set { private: ``` enum NodeColor { kBlack = 0, kRed = 1 Loading Loading
docs/ds/llrbt.md +11 −10 Original line number Diff line number Diff line Loading @@ -76,18 +76,19 @@ } ``` template<class Key, class Compare> typename Set<Key, Compare>::Node * Set<Key, Compare>::insert(Set::Node *root, const Key &key) const { if (root == nullptr) template<class Key, class Compare> typename Set<Key, Compare>::Node_Set<Key, Compare>::insert(Set::Node_root, const Key &key) const {if (root == nullptr) return new Node(key, kRed, 1); if (root->key == key); else if (cmp_(key, root->key)) // if (key < root->key) else if (cmp\_(key, root->key))//if (key < root->key) root->lc = insert(root->lc, key); else root->rc = insert(root->rc, key); return fix_up(root); } ``` ``` ### 删除 Loading Loading @@ -131,8 +132,8 @@ return root; } template <class Key, class Compare> typename Set<Key, Compare>::Node * Set<Key, Compare>::delete_min(Set::Node *root) const { typename Set<Key, Compare>::Node *Set<Key, Compare>::delete_min( Set::Node *root) const { if (root->lc == nullptr) { delete root; return nullptr; Loading @@ -145,7 +146,6 @@ root->lc = delete_min(root->lc); return fix_up(root); } ``` #### 删除任意节点 Loading Loading @@ -203,6 +203,7 @@ template <class Key, class Compare = std::less<Key>> class Set { private: ``` enum NodeColor { kBlack = 0, kRed = 1 Loading