📄 bitree.cpp
字号:
#include <iostream>
using namespace std;
typedef char TElemType;
typedef struct BiTNode
{
TElemType data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
BiTNode *CreateBiTree()
{
BiTNode *t;
TElemType e;
cin>>e;
if(e=='#')
return 0;
else
{
t=new BiTNode;
t->data=e;
t->lchild=CreateBiTree();
t->rchild=CreateBiTree();
return t;
}
}
int InOrder(BiTree t)
{
int k=0;
if(t!=0)
{
if(t->lchild!=0&&t->rchild!=0)
k++;
InOrder(t->lchild);
InOrder(t->rchild);
}
return k;
}
void LeftChild(BiTree T,TElemType e)
{
if(T!=0)
{
if(T->data==e)
if(T->lchild!=0)
cout<<"此结点左孩子为:"<<T->lchild->data<<endl;
else
cout<<"此结点无左孩子!"<<endl;
LeftChild(T->lchild,e);
LeftChild(T->rchild,e);
}
}
void main()
{
BiTree T;
T=CreateBiTree();
cout<<InOrder(T)<<endl;
LeftChild(T,'F');
LeftChild(T,'E');
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -