Binary Tree Traversals ,create binary tree as follow (Figure
来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:英语作业 时间:2024/07/14 08:45:16
Binary Tree Traversals ,create binary tree as follow (Figure-1) in computer
write out the functions of inorder ,preorder ,postorder and levelorder,and output the their results.And compute the leaf number and height of the binary tree.
Hint:You may choose suitable representation,such as linked representation is often used.
不是翻译题,回答请C黏贴代码
![](http://img.wesiedu.com/upload/f/6b/f6b63bc8d91d2a1a0b865f8ae03ed1b5.jpg)
write out the functions of inorder ,preorder ,postorder and levelorder,and output the their results.And compute the leaf number and height of the binary tree.
Hint:You may choose suitable representation,such as linked representation is often used.
不是翻译题,回答请C黏贴代码
![](http://img.wesiedu.com/upload/f/6b/f6b63bc8d91d2a1a0b865f8ae03ed1b5.jpg)
![Binary Tree Traversals ,create binary tree as follow (Figure](/uploads/image/z/7636894-70-4.jpg?t=Binary+Tree+Traversals+%2Ccreate+binary+tree+as+follow+%28Figure)
如有不合题意之处,谅解,可以自己再改改.
#include
using namespace std;
#include
#include
#define OK 1
#define ERROR 0
#define OVERFLOE -2
typedef char ElemType;
const int maxlength=30;//结点个数不超过30个
typedef struct BiTreeNode
{
ElemType data;
struct BiTreeNode*leftchild,*rightchild;
}BiTreeNode,*BiTree;
void createBiTree(BiTree&t)
{
ElemType ch;
cin>>ch;
if(ch=='#')t=NULL;
else
{
if(!(t=new BiTreeNode))
exit(OVERFLOE);
t->data=ch;//生成根节点
createBiTree(t->leftchild);//构造左子树
createBiTree(t->rightchild);//构造右子树
}
}//createBiTree
void Inorder(BiTree&t)//递归函数:中序次序遍历以t为跟的子树
{
if(t!=NULL)
{
Inorder(t->leftchild);
coutleftchild);
coutrightchild);
depthval=1+(depthleft>depthright?depthleft:depthright);
}
return depthval;
}
int countleaf(BiTree t)
{
int m,n;
if(!t)
{
return 0;
}
if(!t->leftchild&&!t->rightchild)
{
return 1;
}
else
{
m=countleaf(t->leftchild);
n=countleaf(t->rightchild);
return (m+n);
}
}
#include"BiTree.h"
void main()
{
cout
#include
using namespace std;
#include
#include
#define OK 1
#define ERROR 0
#define OVERFLOE -2
typedef char ElemType;
const int maxlength=30;//结点个数不超过30个
typedef struct BiTreeNode
{
ElemType data;
struct BiTreeNode*leftchild,*rightchild;
}BiTreeNode,*BiTree;
void createBiTree(BiTree&t)
{
ElemType ch;
cin>>ch;
if(ch=='#')t=NULL;
else
{
if(!(t=new BiTreeNode))
exit(OVERFLOE);
t->data=ch;//生成根节点
createBiTree(t->leftchild);//构造左子树
createBiTree(t->rightchild);//构造右子树
}
}//createBiTree
void Inorder(BiTree&t)//递归函数:中序次序遍历以t为跟的子树
{
if(t!=NULL)
{
Inorder(t->leftchild);
coutleftchild);
coutrightchild);
depthval=1+(depthleft>depthright?depthleft:depthright);
}
return depthval;
}
int countleaf(BiTree t)
{
int m,n;
if(!t)
{
return 0;
}
if(!t->leftchild&&!t->rightchild)
{
return 1;
}
else
{
m=countleaf(t->leftchild);
n=countleaf(t->rightchild);
return (m+n);
}
}
#include"BiTree.h"
void main()
{
cout
Binary Tree Traversals ,create binary tree as follow (Figure
好人一生平安!Binary Tree
Binary Search Tree的缩写是什么阿?
Searching other element in struct in Binary Search Tree in
英语翻译A binary tree(二叉树) is similar to a tree in which every n
The_____of a binary search tree prints the values of the nod
英语翻译set/binary search tree/priority queue(with values in asc
The of a binary search tree prints the values of the nodes i
英语翻译binary tree应该叫什么?还有书上的2-tree又应该翻译成什么?二叉树到底指的是哪个?最好翻译之后,能
英语翻译All field equipment,such as analogue and binary transmit
c++中的ios::binary是什么意思?
tree