二叉树赋值版(部分功能)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
typedef struct BiTreenode
{
    char data;
    struct BiTreenode *lchild,*rchild;
}BiTree;
BiTree *Create_BinaryTree();///创建
void PrePrint_BinaryTree(BiTree *);///先序
void MidPrint_BinaryTree(BiTree *);///中序
void AfterPrint_BinaryTree(BiTree *);///后序
void Find_BinaryTree(BiTree *);///查找
void clear();
int main()
{
    BiTree *Tree;
    int choose;
    do{
        printf("\t\t\t********************\n");
        printf("\t\t\t*1.二叉树的遍历与创建\n");
        printf("\t\t\t*2.先序遍历序列输出\n");
        printf("\t\t\t*3.中序遍历序列输出\n");
        printf("\t\t\t*4.后序遍历序列输出\n");
        printf("\t\t\t*5.查找结点\n");
        printf("\t\t\t*0.退出\n");
        printf("\t\t\t********************\n");
        printf("请输入你需要操作的菜单:");
        scanf("%d",&choose);
        if(choose==0)
        {
            printf("\t\t\t欢迎下次再使用!\n");
            break;
        }
        switch(choose)
        {
            case 1:getchar();Tree=Create_BinaryTree();break;
            case 2:printf("先序遍历序列:");PrePrint_BinaryTree(Tree);puts("");break;
            case 3:printf("中序遍历序列:");MidPrint_BinaryTree(Tree);puts("");break;
            case 4:printf("后序遍历序列:");AfterPrint_BinaryTree(Tree);puts("");break;
            case 5:getchar();Find_BinaryTree(Tree);break;
            default:printf("输入错误,请重新输入\n");break;
        }
        clear();
    }while(1);
    return 0;
}
BiTree *Create_BinaryTree()
{
    char data;
    BiTree *Tree;
    scanf("%c",&data);
    if(data=='0')
        Tree=NULL;
    else
    {
        Tree=(BiTree *)malloc(sizeof(BiTree));
        Tree->data=data;
        Tree->lchild=Create_BinaryTree();
        Tree->rchild=Create_BinaryTree();
    }
    return Tree;
}


void PrePrint_BinaryTree(BiTree *Tree)
{
    if(Tree==NULL)
        return ;
    printf("%c",Tree->data);
    PrePrint_BinaryTree(Tree->lchild);
    PrePrint_BinaryTree(Tree->rchild);
}


void MidPrint_BinaryTree(BiTree *Tree)
{
    if(Tree==NULL)
        return ;
    MidPrint_BinaryTree(Tree->lchild);
    printf("%c",Tree->data);
    MidPrint_BinaryTree(Tree->rchild);
}


void AfterPrint_BinaryTree(BiTree *Tree)
{
    if(Tree==NULL)
        return ;
    AfterPrint_BinaryTree(Tree->lchild);
    AfterPrint_BinaryTree(Tree->rchild);
    printf("%c",Tree->data);
}


void Find_BinaryTree(BiTree *Tree)///查找
{
    char e;
    scanf("%c",&e);
    if(Tree->data==e)
    {
        puts("yes");
        return ;
    }
    AfterPrint_BinaryTree(Tree->lchild);
}


void clear()
{
    printf("请按任意键继续......");
    getch();
    system("cls");
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值