数据结构第五天

     1	#ifndef __HEAD_H__
     2	#define __HEAD_H__
     3	#include <stdio.h>
     4	#include <stdlib.h>
     5	#include <string.h>
     6	typedef char dataType;
     7	typedef struct Tree
     8	{
     9		dataType data;
    10		struct Tree* lchild;
    11		struct Tree* rchild;
    12	} Seq;
    13	Seq* creat_binaryTree();
    14	void show_preo(Seq *root);
    15	void show_Inorder(Seq *root);
    16	void show_post(Seq *root);
    17	#endif
    18	
    19	#include "03_head.h"
    20	
    21	Seq* creat_binaryTree()
    22	{
    23		char value = 0;
    24		scanf("%c",&value);
    25		getchar();
    26		if('#' == value)
    27		{
    28			return NULL;
    29		}
    30		Seq* root = (Seq*)malloc(sizeof(Seq));
    31		if(NULL == root)
    32		{
    33			printf("创建失败\n");
    34			return NULL;
    35		}
    36		root->data = value;
    37		root->lchild = creat_binaryTree();
    38		root->rchild = creat_binaryTree();
    39		return root;
    40	}
    41	void show_preo(Seq *root)
    42	{
    43		if(root != NULL)
    44		{
    45			printf("%c",root->data);
    46			show_preo(root->lchild);
    47			show_preo(root->rchild);
    48		}
    49		return;
    50	}
    51	void show_Inorder(Seq *root)
    52	{
    53		if(NULL == root)
    54		{
    55			return;
    56		}
    57		show_Inorder(root->lchild);
    58		printf("%c",root->data);
    59		show_Inorder(root->rchild);
    60	
    61		return;
    62	}
    63	void show_post(Seq *root)
    64	{
    65		if(NULL == root)
    66		{
    67			return;
    68		}
    69		show_post(root->lchild);
    70		show_post(root->rchild);
    71		printf("%c",root->data);
    72		return;
    73	}
    74	
    75	#include "03_head.h"
    76	int main(int argc, const char *argv[])
    77	{
    78		Seq *binTree = creat_binaryTree();
    79		show_preo(binTree);
    80		putchar(10);
    81		show_Inorder(binTree);
    82		putchar(10);
    83		show_post(binTree);
    84		putchar(10);
    85		return 0;
    86	}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值