设为首页 加入收藏

TOP

C++类实现二叉树的构建和遍历
2017-02-08 08:16:12 】 浏览:364
Tags:实现 建和
C++类实现二叉树的构建和遍历C++类怎么实现二叉树的构建和遍历呢?希望下面的文章对大家有所帮助。
#include
  
   
#include
   
     #include
    
      using namespace std; /*二叉树的结构体*/ typedef struct BTree { int val; struct BTree *left,*right; }BTree; /*二叉树的类,包含着操作二叉树的各种方法*/ class Tree { public: BTree *create_node(int level,string pos); void PreOrder(BTree *t); //先序遍历 void InOrder(BTree *t); //中序遍历 void PostOrder(BTree *t); //后序遍历 BTree *root; }; /*用先序遍历的方法递归构造一课二叉树*/ BTree* Tree::create_node(int level,string pos) { int data; BTree *node = new BTree; cout<<"please enter data:level "<
     
    
   
  
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇c++双向链表构成的队列 下一篇C++ 获取文件下的所有文件的名字

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目