小荆


私信TA

用户名:JHN01

访问量:5658

签 名:

等  级
排  名 2260
经  验 2299
参赛次数 0
文章发表 23
年  龄 0
在职情况 学生
学  校 邯郸学院
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

#include<stdio.h>

#include<stdlib.h>

#define stype char


typedef struct node{

struct node *left;

struct node *right;

stype num;}Node;


void preorder(Node *root)

{

if(root!=NULL)

{

printf("%c ",root->num);

preorder(root->left);

preorder(root->right);

}


}


void inorder(Node *root)

{

if(root!=NULL)

{

inorder(root->left);

printf("%c ",root->num);

inorder(root->right);

}

}


void postorder(Node *root)

{

if(root!=NULL)

{

postorder(root->left);

postorder(root->right);

printf("%c ",root->num);

}

}


//创建二叉树


void BulidBT(Node **tree)   //二级指针

{

char ch;

scanf("%c",&ch);


if(ch==' ')

*tree=NULL;


else

{

*tree=(Node *)malloc(sizeof(Node));

(*tree)->num=ch;

BulidBT(&(*tree)->left);

BulidBT(&(*tree)->right);

}

}


void destroy(Node *root)

{

if(root!=NULL)

{

destroy(root->left);

destroy(root->right);

free(root);

}

}


int main()

{

    Node *tree;

BulidBT(&tree);


preorder(tree);

putchar('\n');


inorder(tree);

    putchar('\n');


    inorder(tree);

putchar('\n');


destroy(tree);

return 0;

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区