• 数据结构之树


    二叉树的使用方法及遍历

    #include "iostream.h"
    template<class T>
    class CTree
    {
    public:
     CTree(const T &item, CTree<T>*lp = NULL, CTree<T>*rp = NULL);
     CTree<T> *GetLp(void) const;
     CTree<T> *GetRp(void) const;
     CTree<T> *GetNode(const &item,CTree<T>*lp = NULL, CTree<T>*rp = NULL);
     void FreeNode(CTree<T>* p);
    public:
     T data;
    private:
     CTree<T> *Left;
     CTree<T> *Right;
    };

    template<class T>
    CTree<T>::CTree(const T &item, CTree<T>*lp, CTree<T>*rp) : data(item), Left(lp), Right(rp)
    {
       
    }

    template<class T>
    CTree<T>* CTree<T>::GetLp(void) const
    {
     return Left;
    }

    template<class T>
    CTree<T>* CTree<T>::GetRp(void) const
    {
     return Right;
    }

    template<class T>
    CTree<T> *CTree<T>::GetNode(const &item,CTree<T>*lp, CTree<T>*rp)
    {
     CTree<T>* p = new CTree<T>(item, lp, rp);
        ASSERT(p);
        return p;
     
    }

    template<class T>
    void CTree<T>::FreeNode(CTree<T>* p)
    {
     delete p;
    }

    void main()
    {
        CTree<int> *root, *lp, *rp;
     lp = new CTree<int>(10);
     rp = new CTree<int>(20);
     root =new CTree<int>(50,lp,rp);
    }

  • 相关阅读:
    Python的可变和不可变类型
    Pycharm设置语法规范快捷键方式
    python学习0305作业
    关于jQuery对象与DOM对象
    ie6下子元素撑大父元素
    Hibernate持久层ORM框架
    基于注解的事务管理
    掌握基于AOP事务管理
    Spring事务管理
    事务保存点savepoint
  • 原文地址:https://www.cnblogs.com/lizhengjin/p/1268072.html
Copyright © 2020-2023  润新知