深圳快速网站制作服务,wordpress调用api,与众不同的网站,网络营销基础网站建设与运营文章目录 一、插入递归二、寻找递归#xff08;非常简单#xff0c;走流程就行#xff09;三、插入递归#xff08;理解起来比较麻烦#xff09; 先赞后看#xff0c;养成习惯#xff01;#xff01;#xff01;^ _ ^3 ❤️ ❤️ ❤️ 码字不易#xff0c;大家的… 文章目录 一、插入递归二、寻找递归非常简单走流程就行三、插入递归理解起来比较麻烦 先赞后看养成习惯^ _ ^3 ❤️ ❤️ ❤️ 码字不易大家的支持就是我坚持下去的动力。点赞后不要忘了关注我哦 所属专栏:C进阶 一、插入递归 bool _InsertR(const K key){return _Insert(_root, key);}
bool _Insert(Node* root, const K key)
{if (root nullptr){root new Node(key);}if (root-_key key){return _Insert(root-left, key);}else if (root-_key key){return _Insert(root-right, key);}else{return false;}
}代码解读
二、寻找递归非常简单走流程就行 bool _FindR(const K key){return _Find(_root, key);}bool _Find(Node* root, const K key)
{if (root nullptr)return false;if (root-_key key){return _Find(root-left,key);}else if (root-_key key){return _Find(root-right,key);}else{return true;}
}三、插入递归理解起来比较麻烦 bool _EraseR(const K key){return _Erase(_root, key);}bool _Erase(Node* root, const K key)
{if (root nullptr)return false;if (root-_key key){return _Erase(root-left, key);}else if (root-_key key){return _Erase(root-right, key);}else{Node* del root;if (root-left nullptr){root root-right;}else if (root-right nullptr){root root-left;}//递归转化到子树去删除else{Node* leftmax root-left;while (leftmax-right){leftmax leftmax-right;}swap(root-_key, leftmax-_key);return _Erase(root-left, key);}delete del;return true;}代码解读