二叉查找树

/*https://www.cnblogs.com/skywang12345/p/3576373.html#aa1*/
/*二叉查找树代码实现*/
#include<bits/stdc++.h>
using namespace std;

template <class t>

class bstnode {
    public:
        t key;//关键字,用来对节点进行排序
        bstnode *left;//左孩子
        bstnode *right;//右孩子
        bstnode *parent;//父节点
        bstnode(t value,bstnode *p,bstnode *l,bstnode *r):
            key(value),parent(),left(l),right(r) {}
};
//表示二叉查找树的节点

template<class t>
class bstree {
    private:
        bstnode<t> *mroot;//根节点
    public:
        bstree();
        ~bstree();
        void preorder();//前序遍历
        void inorder();//中序遍历
        void postorder();//后序遍历
        bstnode<t> * search(t key);//递归实现查找二叉树中键值为key的节点
        bstnode<t> * iterativesearch(t key);//非递归实现查找二叉树中键值为key的节点
        t minimum();//查找最小节点
        t maximum();//查找最大节点
        bstnode<t> * successor(bstnode<t> *x);//找x的数值大于该节点的最小节点,后继结点
        bstnode<t> * predecessor(bstnode<t> *x);//找x的数值小于该节点的最大节点,前驱节点
        void insert(t key);//将节点插入二叉树
        void remove(t key);//删除节点
        void destroy();//销毁二叉树
        void print();//打印二叉树
    private:
        void preorder(bstnode<t> * tree) const;//前序遍历
        void inorder(bstnode<t> * tree) const;//中序遍历
        void postorder(bstnode<t> * tree) const;//后序遍历
        bstnode<t>* search(bstnode<t>* x, t key) const;// (递归实现)查找"二叉树x"中键值为key的节点
        bstnode<t>* iterativesearch(bstnode<t>* x, t key) const;// (非递归实现)查找"二叉树x"中键值为key的节点
        bstnode<t>* minimum(bstnode<t>* tree); // 查找最小结点:返回tree为根结点的二叉树的最小结点。
        bstnode<t>* maximum(bstnode<t>* tree);// 查找最大结点:返回tree为根结点的二叉树的最大结点。
        void insert(bstnode<t>* &tree, bstnode<t>* z);// 将结点(z)插入到二叉树(tree)中
        bstnode<t>* remove(bstnode<t>* &tree, bstnode<t> *z);// 删除二叉树(tree)中的结点(z),并返回被删除的结点
        void destroy(bstnode<t>* &tree);// 销毁二叉树 
        void print(bstnode<t>* tree, t key, int direction);// 打印二叉树
};
template<class t>
void bstree<t>::preorder(bstnode<t>* tree) const
{
    if(tree!=NULL)
    {
        cout<<tree->key <<" ";
        preorder(tree->)
    }
}

int main() {

}
原文地址:https://www.cnblogs.com/yxr001002/p/14185328.html