可能編譯時會有些語法小錯誤(比如分號,->,等),很容易就自己糾正了哦,思路絕對是完全正確的,所以用的話就自己試著改改吧,直接復制粘貼,就正確,豈不是太沒寫代碼體驗了,自己改改才印象更加深刻的呢(▽)~~~~;
#include<iostream>
using namespace std;
typedef struct BiNode{
char data;
struct BiNode *lchild,*rchild;
}BiTNode,*BiTree;
void CreateBiTree(BiTree &T){
char ch;
cin>>ch;
if(ch=='#') T=NULL;
else{
T=new BiTNode;
T->data=https://www.cnblogs.com/ygjzs/p/ch;
CreateBiTree(T->lchild);
CreateBiTree(T->rchild);
}
}
int NodeCount(BiTree T){
if(T==NULL) return 0;
else return NodeCount(T->lchild)+NodeCount(T->rchild)+1;
}
void main(){
BiTree tree;
cout<<"請輸入建立二叉鏈表的序列:\n";
CreateBiTree(tree);
cout<<"結點個數為:"<<NodeCount(tree)<<endl;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/125579.html
標籤:其他
上一篇:求樹的深度
下一篇:中序線索化二叉樹
