?? cpp1.cpp
字號:
#include "iostream.h"
#include "malloc.h"
#define maxsize 100
typedef struct node
{
int data;
struct node *lc,*rc;
}Btree;
typedef struct node *bitreptr,*tpointer;
tpointer nar[maxsize];
bitreptr creat(bitreptr root)
{
int n,i,j,f,x;
cout<<"輸入結點數:";
cin>>n;
for(i=1;i<=n;i++)
{
cout<<"輸入編號:";
cin>>j;
cout<<"輸入值:";
cin>>x;
nar[j]=(bitreptr)malloc(sizeof(Btree));
nar[j]->data=x;
nar[j]->lc=0;
nar[j]->rc=0;
if(j==1)
root=nar[j];
else
{
f=j/2;
if(j%2==0)
nar[f]->lc=nar[j];
else if(j%2!=0)
nar[f]->rc=nar[j];
}
}
return root;
}
int high(bitreptr root)
{
if(!root)
return 0;
else
{
if(high(root->lc)>=high(root->rc))
return (1+(high(root->lc)));
else
return (1+(high(root->rc)));
}
}
void main()
{
bitreptr t=0;
t=creat(t);
cout<<high(t)<<endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -