?? binarytree2.h
字號(hào):
struct Tnode //樹結(jié)點(diǎn)的結(jié)構(gòu)
{
Tnode * left;
Tnode * right;
Tnode * parent;
char data;
int pos; //節(jié)點(diǎn)的位置
};
int size(Tnode *); //計(jì)算樹的結(jié)點(diǎn)個(gè)數(shù)
int level(Tnode *);//計(jì)算結(jié)點(diǎn)層數(shù)
Tnode * creatTree();//創(chuàng)建一棵樹,返回root
Tnode * creatTree()
{
Tnode * a=new Tnode;
a->data='a';
Tnode * b=new Tnode;
b->data='b';
Tnode * c=new Tnode;
c->data='c';
Tnode * d=new Tnode;
d->data='d';
Tnode * e=new Tnode;
e->data='e';
Tnode * f=new Tnode;
f->data='f';
Tnode * g=new Tnode;
g->data='g';
Tnode * h=new Tnode;
h->data='h';
Tnode * i=new Tnode;
i->data='i';
Tnode * j=new Tnode;
j->data='j';
Tnode * k=new Tnode;
k->data='k';
Tnode * l=new Tnode;
l->data='l';
Tnode * m=new Tnode;
m->data='m';
Tnode * n=new Tnode;
n->data='n';
n->left=NULL;n->right=NULL;n->parent=e;
m->left=NULL;m->right=NULL;m->parent=i;
l->left=NULL;l->right=NULL;l->parent=e;
k->left=NULL;k->right=NULL;k->parent=j;
j->left=k;j->right=NULL;j->parent=i;
h->left=i;h->right=NULL;h->parent=f;
i->left=j;i->right=m;i->parent=h;
g->left=NULL;g->right=NULL;g->parent=f;
f->left=g;f->right=h;f->parent=a;
d->left=NULL;d->right=NULL;d->parent=c;
e->left=n;e->right=l;e->parent=b;
c->left=NULL;c->right=d;c->parent=b;
a->left=b;a->right=f;a->parent=NULL;
b->left=c;b->right=e;b->parent=a;
return a;
}
int size(Tnode * root)
{
if(root==NULL)
return 0;
else
return 1+size(root->left)+size(root->right);
}
int level(Tnode * root)
{
if(root==NULL)
return 0;
else
{
int count=1;
for(;root!=NULL;count++)
root=root->parent;
return count;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -