判断任意给定的二叉树是否为满二叉树

设二叉树采用二叉链表存储,试编写一个判断任意给定的二叉树是否为满二叉树的算法。

#include<stdio.h>

#include<stdlib.h>

typedef struct BiTnode  

{  

        int data;  

        struct BiTnode* Lchild,*Rchild;   

}BiTnode,*BiTree;  

  

void create(BiTree &S)  

{  

        char ch;  

        char temp;  

        scanf(“%c”,&ch);  

        temp=getchar();  

        if(ch==’#’)  

        {  

                S=NULL;  

        }  

        else  

        {  

                S=(BiTree)malloc(sizeof(BiTnode) );  

                if(!S)  

                {  

                    exit(0);  

                }  

                else  

                {  

                        S->data=ch;  

                         

                        create(S->Lchild);  

                        

                        create(S->Rchild);  

                }  

  

        }  

        return;  

  

}

int full(BiTree S){

if(S->Lchild ==NULL&&S->Rchild ==NULL)

return 1;

else if(S->Lchild ==NULL||S->Rchild ==NULL)

return 0;

else

return 0;

}

int main()

{  

     BiTree S;

 printf(“创建一个树\n”);       

     create(S);   

     if(full(S))

     printf(“满二叉树\n”);

 else

     printf(“不是满二叉树\n”);

     return 0;

 }

    原文作者:满二叉树
    原文地址: https://blog.csdn.net/printf88/article/details/78403123
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞