概述
#include <iostream>
#include <cstdlib>
using namespace std;
struct BinTreeNode{
int date;
BinTreeNode *liftChild, *rightChild;
}
class BinaryTree{
public:
BinaryTree();
BinaryTree(BinaryTree &s);
~BinaryTree();
void CreateBinTree(BinTreeNode *&SubTree);
bool IsEmpty();
void InOrder();
void InOrder(BinTreeNode *subTree);
void PreOrder();
void PreOrder(BinTreeNode *subTree);
void PostOrder();
void PostOrder(BinTreeNode *subTree);
int Count();
int Count(BinTreeNode *subTree);
private:
BinTreeNode *root;
};
//构造函数
BinaryTree::BinaryTree():root(NULL){}
BinaryTree::BinaryTree(BinaryTree &s){
}
//判空
bool BinaryTree::IsEmpty(){
return root == NULL ? true : false;
}
//中序遍历
void BinaryTree::InOrder(){
InOrder(root);
}
void BinaryTree::InOrder(BinTreeNode *subTree){
if(subTree != NULL){
InOrder(subTree->liftChild);
cout << subTree->date;
InOrder(subTree->rightChild);
}
}
//先序遍历
void BinaryTree::PreOrder(){
PreOrder(root);
}
void BinaryTree::PreOrder(BinTreeNode *subTree){
if(subTree != NULL){
cout << subTree->date;
PreOrder(subTree->liftChild);
PreOrder(subTree->rightChild);
}
}
//后续遍历
void BinaryTree::PostOrder(){
PostOrder(root);
}
void BinaryTree::PostOrder(BinTreeNode *subTree){
if(subTree != NULL){
PostOrder(subTree->liftChild);
PostOrder(subTree->rightChild);
cout << subTree->date;
}
}
int main(){
system("pause");
return 0;
}
最后
以上就是要减肥冰棍为你收集整理的数据结构二叉树——递归遍历的全部内容,希望文章能够帮你解决数据结构二叉树——递归遍历所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复