c语言完全二叉树原理,C语言判断完全二叉树
滿(mǎn)意答案
MiC資訊
2013.04.27
采納率:45%????等級(jí):12
已幫助:15954人
lz
完成了
#include "stdio.h"
#include "stdlib.h"
#define Max 100
typedef struct Node
{
char data;
struct Node * LChild,*RChild;
}BiTNode,*BiTree;
void CreateBiTree(BiTree * bt)
{
char ch;
ch=getchar();
if(ch==10)ch=getchar();//如果為 回車(chē)換行 讀取下一個(gè)字符
if(ch=='.') *bt=NULL; //如果為 . 代表此節(jié)點(diǎn)為空
else
{
* bt=(BiTree)malloc(sizeof(BiTNode));
(* bt)->data=ch; //賦值
CreateBiTree(&((* bt)->LChild));
CreateBiTree(&((* bt)->RChild));
}
}
bool fullBiTree(BiTree b)
{
if(b->LChild==NULL && b->RChild==NULL)return true;//如果左右子樹(shù)為空,返回真
if(b->LChild==NULL || b->RChild==NULL)return false;//如果左右子樹(shù)只有一個(gè)為空,返回假
return fullBiTree(b->LChild) && fullBiTree(b->RChild);//通過(guò)遞歸,返回 交
}
void main()
{
printf("此二叉樹(shù)是對(duì)字符進(jìn)行存儲(chǔ)\n\n");
printf("請(qǐng)依次輸入字符(范例\n不是完全二叉樹(shù)ABCO..UMJKL.EDC..........\n完全二叉樹(shù)ABC..DE..F..G..)\n");
BiTree b;
CreateBiTree(&b); //創(chuàng)建二叉樹(shù)
bool cm=fullBiTree(b);
if(cm)printf("此二叉樹(shù)為完全二叉樹(shù)\n");
else printf("此二叉樹(shù)不是完全二叉樹(shù)\n");
}
14分享舉報(bào)
總結(jié)
以上是生活随笔為你收集整理的c语言完全二叉树原理,C语言判断完全二叉树的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 同花顺炒股软件下载|炒股软件下载
- 下一篇: 锤子t2 android7.0,锤子手机