二叉搜索树(Binary Search Tree)的递归和非递归代码实现(C++)
来源:互联网 发布:淘宝怎么买高仿包包 编辑:程序博客网 时间:2024/05/28 11:30
二叉搜索树简单介绍
二叉搜索树(Binary Search Tree)是满足:
- 左子树的根节点比树的根节点小
- 右子树的根节点比树的根节点大
的二叉树。
由于这种数据结构具有很高的查询效率,故多用于需要索引的场合。
二叉搜索树的搜索过程可以理解成类二分查找,因为根节点就等效于一串数据的分界点,左子树的所有节点都小于根节点,右子树的所有节点都大于根节点,然后每次比较都能确定元素属于哪一部分,故查询效率为O(nlogn)。
查找
根据二叉搜索数的性质有:
- 大于节点key的元素在右子树
- 小于节点key的元素在左子树
在二叉搜索树中查找指定元素 k(node表示当前搜索节点):
- 递归思路:
若 k > node->key,搜索 node->rNode
若 k < node->key,搜索 node->lNode
若 k = node->key,返回 node->val - 非递归思路
设置一个用来遍历节点的指针p
若 k > p->key,p = p->rNode
若 k < p->key,p = p->lNode
若 k = p->key,返回 p->val
插入
首先需要寻找到插入位置,在寻找位置的过程中如果发现有相同key则更新该key对应的value,否则插入新的节点
- 递归思路:
递归出口:node = NULL,创建新节点并用 key 和 val 初始化
若 k > node->key,node->lNode = put(node->lNode, key)
若 k < node->key,node->rNode = put(node->rNode, key)
若 k = node->key,node->val = val
当前节点个数 = 左子树节点个数 + 右子树节点个数 + 1
- 非递归思路:
设置一个堆栈和遍历指针 p,p 的父节点指针 pa
将经过的节点都记录到堆栈中,如果找到重复节点则更新值并清空堆栈。
否则新建节点并用 key 和 val 初始化,并将 pa 指向 p,同时栈中所有节点的节点个数 N 增加1
删除
- 递归思路:
和插入类似,只是在key = node->key的时候需要分情况:
若 node->rNode 不为空,则找到 node->rNode 子树的最小节点min并将node->key = min->key,node->val = min->val,然后删除该最小节点
若 node->rNode 为空,node->lNode 不为空,则直接 node = node ->lNode
若 node->rNode 为空,node->lNode 为空,则直接 node = NULL - 非递归思路:
和递归类似,只是需要遍历堆栈去更新遍历路径上的节点数 N
代码实现
递归版本
//BSTR.h#ifndef BSTR_H#define BSTR_H#include <iostream>template<typename K, typename V>struct Node{ K key; V val; int N; Node<K,V>* lNode; Node<K,V>* rNode; Node() { this->lNode = NULL; this->rNode = NULL; } Node(K key, V val) { this->key = key; this->val = val; this->lNode = NULL; this->rNode = NULL; this->N = 1; }};template<typename K, typename V>class BST{public: BST(); ~BST(); V get(const K& key) const; void put(const K& key, const V& val); void del(const K& key); bool contain(const K& key) const; int size() const; void clean(); void print() const; K floor(const K& key) const; K celling(const K& key) const; int rank(const K& key) const; K select(int rk) const; K minKey() const; K maxKey() const; void delMin(); void delMax();protected: Node<K,V>* root; V get(Node<K,V>* node, const K& key) const; void clean(Node<K,V>* node); Node<K,V>* put(Node<K,V>* node, const K& key, const V& val); Node<K,V>* del(Node<K,V>* node, const K& key); bool contain(Node<K,V>* node, const K& key) const; int size(Node<K,V>* node) const; void print(Node<K,V>* node) const; K floor(Node<K,V>* node, const K& key) const; K celling(Node<K,V>* node, const K& key) const; int rank(Node<K,V>* node, const K& key) const; K select(Node<K,V>* node, int rk) const; K minKey(Node<K,V>* node) const; K maxKey(Node<K,V>* node) const; Node<K,V>* delMin(Node<K,V>* node); Node<K,V>* delMax(Node<K,V>* node);};//构造 析构函数template<typename K, typename V>BST<K,V>::BST(){ this->root = NULL;}template<typename K, typename V>BST<K,V>::~BST(){ if (this->root != NULL) clean(this->root);}/******************************************************************** 函数名称: clean函数说明: 清空表返回值: 无 *********************************************************************/template<typename K, typename V>void BST<K,V>::clean(){ clean(this->root); this->root = NULL;}template<typename K, typename V>void BST<K,V>::clean(Node<K,V>* node){ if (node == NULL) return ; clean(node->lNode); clean(node->rNode); delete node;}/******************************************************************** 函数名称: size函数说明: 无返回值: 表的大小*********************************************************************/template<typename K, typename V>int BST<K,V>::size() const{ return size(this->root);}template<typename K, typename V>int BST<K,V>::size(Node<K,V>* node) const{ if (node != NULL) return node->N; else return 0;}/******************************************************************** 函数名称: put函数说明: 放入键值对<key,value> 若存在则将原有的value替换成新的value返回值: 无*********************************************************************/template<typename K, typename V>void BST<K,V>::put(const K& key, const V& val){ this->root = put(this->root, key, val);}template<typename K, typename V>Node<K,V>* BST<K,V>::put(Node<K,V>* node, const K& key, const V& val){ if (node == NULL) return new Node<K,V>(key ,val); if (key > node->key) node->rNode = put(node->rNode, key, val); else if (key < node->key) node->lNode = put(node->lNode, key, val); else node->val = val; node->N = size(node->lNode) + size(node->rNode) + 1; return node;}/******************************************************************** 函数名称: get函数说明: 获取指定key的value返回值: value*********************************************************************/template<typename K, typename V>V BST<K,V>::get(const K& key) const{ return get(this->root, key);}template<typename K, typename V>V BST<K,V>::get(Node<K,V>* node, const K& key) const{ if (node == NULL) return NULL; if (key > node->key) return get(node->rNode, key); else if (key < node->key) return get(node->lNode, key); else return node->val;}/******************************************************************** 函数名称: del函数说明: 删除某个key返回值: 无*********************************************************************/template<typename K, typename V>void BST<K,V>::del(const K& key){ this->root = del(this->root, key);}template<typename K, typename V>Node<K,V>* BST<K,V>::del(Node<K,V>* node, const K& key){ if (node == NULL) return NULL; if (key > node->key) node->rNode = del(node->rNode, key); else if (key < node->key) node->lNode = del(node->lNode, key); else { Node<K,V>* newNode; if (node->lNode == NULL && node->rNode == NULL) return NULL; else if (node->lNode != NULL && node->rNode == NULL) { newNode = node->lNode; delete node; node = newNode; } else if (node->lNode == NULL && node->rNode != NULL) { newNode = node->rNode; delete node; node = newNode; } else { node->key = minKey(node->rNode); node->val = get(node->key); node->rNode = delMin(node->rNode); } } node->N = size(node->lNode) + size(node->rNode) + 1; return node;}/******************************************************************** 函数名称: print函数说明: 打印表中内容返回值: 无*********************************************************************/template<typename K, typename V>void BST<K,V>::print() const{ print(this->root);}template<typename K, typename V>void BST<K,V>::print(Node<K,V>* node) const{ if (node == NULL) return; print(node->lNode); std::cout << node->key << ":" << node->val << " : " << node->N << std::endl; print(node->rNode);}/******************************************************************** 函数名称: contain函数说明: 是否包含key返回值: 包含返回true 不包含返回false*********************************************************************/template<typename K, typename V>bool BST<K,V>::contain(const K& key) const{ return contain(this->root, key);}template<typename K, typename V>bool BST<K,V>::contain(Node<K,V>* node, const K& key) const{ if (node == NULL) return false; if (key > node->key) contain(node->rNode, key); else if (key < node->key) contain(node->lNode, key); else return true;}/******************************************************************** 函数名称: floor函数参数: key函数说明: 寻找表中小于等于key的最大key返回值: key*********************************************************************/template<typename K, typename V>K BST<K,V>::floor(const K& key) const{ return floor(this->root, key);}template<typename K, typename V>K BST<K,V>::floor(Node<K,V>* node, const K& key) const{ static K mKey; if (node == NULL) return mKey; if (key > node->key) { mKey = node->key; floor(node->rNode, key); } else if (key < node->key) floor(node->lNode, key); else return node->key;}/******************************************************************** 函数名称: celling函数参数: key函数说明: 寻找表中大于等于key的最小key返回值: key*********************************************************************/template<typename K, typename V>K BST<K,V>::celling(const K& key) const{ return celling(this->root, key);}template<typename K, typename V>K BST<K,V>::celling(Node<K,V>* node, const K& key) const{ static K mKey; if (node == NULL) return mKey; if (key > node->key) celling(node->rNode, key); else if (key < node->key) { mKey = node->key; celling(node->lNode, key); } else return node->key;}/******************************************************************** 函数名称: rank函数参数: key的值函数说明: 在表中找出小于等于key值的元素个数返回值: key的个数*********************************************************************/template<typename K, typename V>int BST<K,V>::rank(const K& key) const{ return rank(this->root, key);}template<typename K, typename V>int BST<K,V>::rank(Node<K,V>* node, const K& key) const{ if (node == NULL) return 0; if (key >= node->key) return size(node->lNode) + 1 + rank(node->rNode, key); else return rank(node->lNode, key);}/******************************************************************** 函数名称: select函数参数: 元素个数函数说明: 在表中按从小到大的顺序找出第 k 个key返回值: key*********************************************************************/template<typename K, typename V>K BST<K,V>::select(int rk) const{ return select(this->root, rk);}template<typename K, typename V>K BST<K,V>::select(Node<K,V>* node, int rk) const{ int N; if (rk > this->root->N) rk = this->root->N; if (node->lNode != NULL) N = node->lNode->N; else N = 0; if (rk <= N) return select(node->lNode, rk); else if (rk == (N + 1)) return node->key; else return select(node->rNode, rk - N - 1);}/******************************************************************** 函数名称: minKey函数参数: 无函数说明: 返回表中最小的key返回值: key*********************************************************************/template<typename K, typename V>K BST<K,V>::minKey() const{ return minKey(this->root);}template<typename K, typename V>K BST<K,V>::minKey(Node<K,V>* node) const{ if (node->lNode == NULL) return node->key; minKey(node->lNode);}/******************************************************************** 函数名称: maxKey函数参数: 无函数说明: 返回表中最大的key返回值: key*********************************************************************/template<typename K, typename V>K BST<K,V>::maxKey() const{ return maxKey(this->root);}template<typename K, typename V>K BST<K,V>::maxKey(Node<K,V>* node) const{ if (node->rNode == NULL) return node->key; maxKey(node->rNode);}/******************************************************************** 函数名称: delMin函数参数: 无函数说明: 删除表中最小key返回值: 无*********************************************************************/template<typename K, typename V>void BST<K,V>::delMin(){ this->root = delMin(this->root);}template<typename K, typename V>Node<K,V>* BST<K,V>::delMin(Node<K,V>* node){ if (node->lNode == NULL) { Node<K,V>* rNode = node->rNode; delete node; return rNode; } else node->lNode = delMin(node->lNode); node->N = size(node->lNode) + size(node->rNode) + 1; return node;}/******************************************************************** 函数名称: delMax函数参数: 无函数说明: 删除表中最大key返回值: 无*********************************************************************/template<typename K, typename V>void BST<K,V>::delMax(){ this->root = delMax(this->root);}template<typename K, typename V>Node<K,V>* BST<K,V>::delMax(Node<K,V>* node){ if (node->rNode == NULL) { Node<K,V>* lNode = node->lNode; delete node; return lNode; } else node->rNode = delMax(node->rNode); node->N = size(node->lNode) + size(node->rNode) + 1; return node;}#endif#endif
非递归版本
#ifndef BST_H#define BST_H#include <iostream>#include <stack>template<typename K, typename V>struct Node{ K key; V val; int N; Node<K,V>* lNode; Node<K,V>* rNode; Node() { this->lNode = NULL; this->rNode = NULL; this->N = 1; } Node(K key, V val) { this->key = key; this->val = val; this->lNode = NULL; this->rNode = NULL; this->N = 1; }};template<typename K, typename V>class BST : public ST<K,V>{public: BST(); ~BST(); V get(const K& key) const; void put(const K& key, const V& val); void del(const K& key); bool contain(const K& key) const; int size() const; void clean(); void print() const; K floor(const K& key) const; K celling(const K& key) const; int rank(const K& key) const; K select(int rk) const; K minKey() const; K maxKey() const; void delMin(); void delMax();protected: Node<K,V>* root; std::stack<Node<K,V>*> *s; //辅助堆栈 int size(Node<K,V>* node) const; void print(Node<K,V>* node) const; void insNode(Node<K,V>* node, Node<K,V>* theNode); Node<K,V>* findPos(Node<K,V>* node, const K& key) const;};//构造 析构函数template<typename K, typename V>BST<K,V>::BST(){ this->root = NULL; this->s = new std::stack<Node<K,V>*>;}template<typename K, typename V>BST<K,V>::~BST(){ clean();}/******************************************************************** 函数名称: get函数说明: 获取指定key的value返回值: value*********************************************************************/template<typename K, typename V>V BST<K,V>::get(const K& key) const{ if (this->root == NULL) return NULL; Node<K,V>* tNode = findPos(this->root, key); if (tNode->key != key) return NULL; else return tNode->val;}/******************************************************************** 函数名称: put函数说明: 放入键值对<key,value> 若存在则将原有的value替换成新的value返回值: 无*********************************************************************/template<typename K, typename V>void BST<K,V>::put(const K& key, const V& val){ if (this->root == NULL) this->root = new Node<K,V>(key, val); else { Node<K,V>* tNode = findPos(this->root, key); if (tNode->key != key) { insNode(tNode, new Node<K,V>(key, val)); while (!this->s->empty()) { this->s->top()->N++; this->s->pop(); } } else { tNode->val = val; } }}/******************************************************************** 函数名称: del函数说明: 删除某个key返回值: 无*********************************************************************/template<typename K, typename V>void BST<K,V>::del(const K& key){ Node<K,V> *parentNode = NULL, *currentNode = this->root; //清空堆栈 while (!this->s->empty()) this->s->pop(); //寻找被删除的节点以及该节点的父节点 while (currentNode != NULL) { if (key == currentNode->key) break; this->s->push(parentNode = currentNode); if (key > currentNode->key) currentNode = currentNode->rNode; else currentNode = currentNode->lNode; } //没有寻找到需要删除的节点 if (currentNode == NULL) return ; if (currentNode == this->root) //删除的节点是根节点 { if (currentNode->lNode == NULL) this->root = currentNode->rNode; else if (currentNode->rNode == NULL) this->root = currentNode->lNode; else { //把右子树插入左子树中 insNode(findPos(this->root = currentNode->lNode, currentNode->rNode->key), currentNode->rNode); while (!this->s->empty()) { this->s->top()->N += size(currentNode->rNode); this->s->pop(); } } } else //删除的节点是非根节点 { //父指针置 NULL if (currentNode == parentNode->lNode) parentNode->lNode = NULL; else parentNode->rNode = NULL; while (!this->s->empty()) { this->s->top()->N -= size(currentNode); this->s->pop(); } if (currentNode->lNode != NULL) { insNode(findPos(this->root, currentNode->lNode->key), currentNode->lNode); while (!this->s->empty()) { this->s->top()->N += size(currentNode->lNode); this->s->pop(); } } if (currentNode->rNode != NULL) { insNode(findPos(this->root, currentNode->rNode->key), currentNode->rNode); while (!this->s->empty()) { this->s->top()->N += size(currentNode->rNode); this->s->pop(); } } } delete currentNode;}/******************************************************************** 函数名称: size函数说明: 无返回值: 表的大小*********************************************************************/template<typename K, typename V>int BST<K,V>::size() const{ return size(this->root);}template<typename K, typename V>int BST<K,V>::size(Node<K,V>* node) const{ if (node == NULL) return NULL; return node->N;}/******************************************************************** 函数名称: clean函数说明: 清空表 采用层序遍历返回值: 无 *********************************************************************/template<typename K, typename V>void BST<K,V>::clean(){ if (this->root == NULL) return ; int currentPos = 0, i = 0; int TSize = size(); Node<K,V>** nodeList = new Node<K,V>*[TSize]; nodeList[i++] = this->root; while (currentPos < TSize) { if (nodeList[currentPos]->lNode != NULL) nodeList[i++] = nodeList[currentPos]->lNode; if (nodeList[currentPos]->rNode != NULL) nodeList[i++] = nodeList[currentPos]->rNode; delete nodeList[currentPos]; currentPos++; } delete[] nodeList; this->root = NULL;}/******************************************************************** 函数名称: print函数说明: 打印表中内容返回值: 无*********************************************************************/template<typename K, typename V>void BST<K,V>::print() const{ //print(this->root); std::stack<Node<K,V>*> x; Node<K,V>* currentNode = this->root; //std::stack<Node<K,V>*> f; //中序遍历非递归 while (1) { while (currentNode != NULL) { x.push(currentNode); currentNode = currentNode->lNode; } while (!x.empty() && x.top()->rNode == NULL) { std::cout << x.top()->key << " : " << x.top()->val << std::endl; x.pop(); } if (x.empty()) break; std::cout << x.top()->key << " : " << x.top()->val << std::endl; currentNode = x.top()->rNode; x.pop(); } //前序遍历非递归 //while (1) //{ // while (currentNode != NULL) // { // std::cout << currentNode->key << " : " << currentNode->val << std::endl; // if (currentNode->rNode != NULL) // x.push(currentNode->rNode); // currentNode = currentNode->lNode; // } // if (x.empty()) // break; // currentNode = x.top(); // x.pop(); //} //后序遍历非递归 //while (1) //{ // while (currentNode != NULL) // { // x.push(currentNode); // currentNode = currentNode->lNode; // } // while (!x.empty() && x.top()->rNode == NULL) // { // std::cout << x.top()->key << " : " << x.top()->val << std::endl; // x.pop(); // } // while (!x.empty() && !f.empty() && x.top() == f.top()) // { // std::cout << x.top()->key << " : " << x.top()->val << std::endl; // x.pop(); // f.pop(); // } // if (x.empty()) // break; // if (x.top()->rNode != NULL) // f.push(x.top()); // currentNode = x.top()->rNode; //}}template<typename K, typename V>void BST<K,V>::print(Node<K,V>* node) const{ if (node == NULL) return; print(node->lNode); std::cout << node->key << ":" << node->val << " " << node->N << std::endl; print(node->rNode);}/******************************************************************** 函数名称: contain函数说明: 是否包含key返回值: 包含返回true 不包含返回false*********************************************************************/template<typename K, typename V>bool BST<K,V>::contain(const K& key) const{ return findPos(this->root, key)->key == key;}/******************************************************************** 函数名称: findPos函数说明: 寻找 键值为key的节点 或 该节点插入树时父节点的位置返回值: 指向该节点的指针*********************************************************************/template<typename K, typename V>Node<K,V>* BST<K,V>::findPos(Node<K,V>* node, const K& key) const{ //递归版本 //if (key > node->key) //{ // if (node->rNode == NULL) // return node; // else // return findPos(node->rNode, key); //} //else if (key < node->key) //{ // if (node->lNode == NULL) // return node; // else // return findPos(node->lNode, key); //} //else // return node; //非递归 if (this->root == NULL) return NULL; while (!this->s->empty()) this->s->pop(); while(1) { this->s->push(node); if (key > node->key) { if (node->rNode == NULL) return node; else node = node->rNode; } else if (key < node->key) { if (node->lNode == NULL) return node; else node = node->lNode; } else return node; }}/******************************************************************** 函数名称: insNode函数参数: 插入节点和待插入节点函数说明: 将一棵树插入另一棵树上返回值: 无*********************************************************************/template<typename K, typename V>void BST<K,V>::insNode(Node<K,V>* node, Node<K,V>* theNode){ if (theNode->key > node->key) node->rNode = theNode; else node->lNode = theNode;}/******************************************************************** 函数名称: floor函数参数: key函数说明: 寻找表中小于等于key的最大key返回值: key*********************************************************************/template<typename K, typename V>K BST<K,V>::floor(const K& key) const{ if (this->root == NULL) return NULL; Node<K,V>* currentNode = this->root; K mKey; while (currentNode != NULL) { if (key > currentNode->key) { mKey = currentNode->key; currentNode = currentNode->rNode; } else if (key < currentNode->key) currentNode = currentNode->lNode; else return currentNode->key; } return mKey;}/******************************************************************** 函数名称: celling函数参数: key函数说明: 寻找表中大于等于key的最小key返回值: key*********************************************************************/template<typename K, typename V>K BST<K,V>::celling(const K& key) const{ if (this->root == NULL) return NULL; Node<K,V>* currentNode = this->root; K mKey; while (currentNode != NULL) { if (key > currentNode->key) currentNode = currentNode->rNode; else if (key < currentNode->key) { mKey = currentNode->key; currentNode = currentNode->lNode; } else return currentNode->key; } return mKey;}/******************************************************************** 函数名称: minKey函数参数: 无函数说明: 返回表中最小的key返回值: key*********************************************************************/template<typename K, typename V>K BST<K,V>::minKey() const{ if (this->root == NULL) return NULL; Node<K,V>* currentNode = this->root; while (currentNode->lNode != NULL) currentNode = currentNode->lNode; return currentNode->key;}/******************************************************************** 函数名称: maxKey函数参数: 无函数说明: 返回表中最大的key返回值: key*********************************************************************/template<typename K, typename V>K BST<K,V>::maxKey() const{ if (this->root == NULL) return NULL; Node<K,V>* currentNode = this->root; while (currentNode->rNode != NULL) currentNode = currentNode->rNode; return currentNode->key;}/******************************************************************** 函数名称: delMin函数参数: 无函数说明: 删除表中最小key返回值: 无*********************************************************************/template<typename K, typename V>void BST<K,V>::delMin(){ if (this->root == NULL) return ; while (!this->s->empty()) this->s->pop(); Node<K,V>* currentNode = this->root; while (currentNode->lNode != NULL) { this->s->push(currentNode); currentNode = currentNode->lNode; } if (currentNode->rNode != NULL) this->s->top()->lNode = currentNode->rNode; else this->s->top()->lNode = NULL; delete currentNode; while (!this->s->empty()) { this->s->top()->N--; this->s->pop(); }}/******************************************************************** 函数名称: delMax函数参数: 无函数说明: 删除表中最大key返回值: 无*********************************************************************/template<typename K, typename V>void BST<K,V>::delMax(){ if (this->root == NULL) return ; while (!this->s->empty()) this->s->pop(); Node<K,V>* currentNode = this->root; while (currentNode->rNode != NULL) { this->s->push(currentNode); currentNode = currentNode->rNode; } if (currentNode->lNode != NULL) this->s->top()->rNode = currentNode->lNode; else this->s->top()->rNode = NULL; delete currentNode; while (!this->s->empty()) { this->s->top()->N--; this->s->pop(); }}/******************************************************************** 函数名称: rank函数参数: key的值函数说明: 在表中找出小于等于key值的元素个数返回值: key的个数*********************************************************************/template<typename K, typename V>int BST<K,V>::rank(const K& key) const{ if (this->root == NULL) return NULL; int num = 0; Node<K,V>* currentNode = this->root; while (currentNode != NULL) { if (key >= currentNode->key) { num += (size(currentNode->lNode) + 1); currentNode = currentNode->rNode; } else currentNode = currentNode->lNode; } return num;}/******************************************************************** 函数名称: select函数参数: 元素个数函数说明: 在表中按从小到大的顺序找出第 k 个key返回值: key*********************************************************************/template<typename K, typename V>K BST<K,V>::select(int rk) const{ if (this->root == NULL) return NULL; Node<K,V>* currentNode = this->root; int num = rk; if (num > size()) num = size(); while(currentNode != NULL) { if (num == size(currentNode->lNode) + 1) return currentNode->key; else if (num > size(currentNode->lNode)) { num -= (size(currentNode->lNode) + 1); currentNode = currentNode->rNode; } else currentNode = currentNode->lNode; } return NULL;}#endif
0 0
- 二叉搜索树(Binary Search Tree)的递归和非递归代码实现(C++)
- 二叉搜索树(Binary Search Tree)的递归和非递归代码实现(C++)
- leetcode 99. Recover Binary Search Tree 二叉树非递归遍历,利用stack和morris遍历
- leetcode 108. Convert Sorted Array to Binary Search Tree-数组转搜索树|递归|非递归
- 二叉搜索树的非递归实现
- Binary Search二分法搜索递归和非递归C++程序
- 二叉搜索树(递归和非递归分别实现)
- 编程算法 - 二叉搜索树(binary search tree) 代码(C)
- 二叉搜索树递归&&非递归的基本实现
- 【数据结构】二叉搜索树的递归与非递归实现
- 二叉搜索树的递归遍历和非递归遍历
- LeetCode Binary Tree Postorder Traversal(二叉树的后序遍历 非递归实现)
- 编程算法 - 二叉搜索树(binary search tree) 集合(set)和映射(map) 代码(C)
- 二叉树深度搜索-递归和非递归的实现(转载)
- Leetcode 226: Invert Binary Tree(二叉树反转 递归、非递归实现)
- 【LeetCode】 Invert Binary Tree(二叉树反转 递归、非递归实现)
- 【LeetCode】Convert Sorted Array to Binary Search Tree ---递归建立二叉搜索树
- [数据结构]10.2实现binary search tree的查找和插入操作,用非递归的方法实现
- Linux SAMBA 共享服务器搭建
- 栈的应用之二进制转换为十进制,八进制和十六进制
- Xcode开发的常见问题与解决方案
- Android view手势拖动和缩放
- VS2012 + EF6.x + MySql 开发环境搭建问题 --- 终结篇
- 二叉搜索树(Binary Search Tree)的递归和非递归代码实现(C++)
- 栈应用之使用逆波兰输入求表达式的值
- 不使用中间变量交换a,b值
- 在adb中给android文件开通所有权限
- linux的mount(挂载)命令详解
- 原生Javascript封装的一些常用函数
- 【POJ 2352】Stars
- Android Material Design(3) CardView的使用
- iiOS 开发基础:UIImageView属性