typedef struct BiTNode //二叉树结点
{
char data; //数据
struct BiTNode *lchild,*rchild; //左右孩子指针
}BiTNode,*BiTree;
3. 主要代码结构
int CreateBiTree(BiTree &T)//按先序序列创建二叉树
void Visit(BiTree T)//输出
void PreOrder(BiTree T)//先序遍历
void InOrder(BiTree T) //中序遍历
void PostOrder(BiTree T)//后序遍历
void LevelOrder(BiTree T) //层次遍历
void InOrder2(BiTree T)//非递归中序遍历
int CountLeaf (BiTree T, int& count)//统计叶子结点个数
int Depth (BiTree T ) // 返回二叉树的深度
int main()
选作:通过递归和非递归求值
主要代码结构(全部代码在后面)
#include<stdio.h>
#include<stack>
#include<queue>
#include<iostream>
using namespace std;
int f(int n)
{ …..
return f(n-1)+f(n-2);
}
int fun(int n )
{
for(int i = 2;i<n;i++)
{ ans = b+a; a=b; b=ans;
}
return ans;
}
int main()
{ int n=40 ,m,s;
m=f(n);
s=fun(n);
cout<<"递归算法"<<endl<<m<<endl<<"非递归算法"<<endl<<s<<endl;
return 0;
}