首页 > 编程语言 > 详细

PTA数据结构与算法题目集(中文)6-11 先序输出叶结点 (15分)

时间:2020-03-09 00:34:35      阅读:241      评论:0      收藏:0      [点我收藏+]
 1 // #include <stdio.h>
 2 // #include <stdlib.h>
 3 
 4 // typedef char ElementType;
 5 // typedef struct TNode *Position;
 6 // typedef Position BinTree;
 7 // struct TNode{
 8 //     ElementType Data;
 9 //     BinTree Left;
10 //     BinTree Right;
11 // };
12 
13 // BinTree CreatBinTree(); /* 实现细节忽略 */
14 // void PreorderPrintLeaves( BinTree BT );
15 
16 // int main()
17 // {
18 //     BinTree BT = CreatBinTree();
19 //     printf("Leaf nodes are:");
20 //     PreorderPrintLeaves(BT);
21 //     printf("\n");
22 
23 //     return 0;
24 // }
25 
26 void PreorderPrintLeaves( BinTree BT )
27 {
28     if (!BT)
29     {
30 
31     }
32     else if (!BT->Left && !BT->Right)
33     {
34         printf(" %c", BT->Data);
35     }
36     else if (!BT->Right && BT->Left)
37     {
38         PreorderPrintLeaves(BT->Left);
39     }
40     else if (!BT->Left && BT->Right)
41     {
42         PreorderPrintLeaves(BT->Right);
43     }
44     else
45     {
46         PreorderPrintLeaves(BT->Left);
47         PreorderPrintLeaves(BT->Right);
48 
49     }
50 }

 

PTA数据结构与算法题目集(中文)6-11 先序输出叶结点 (15分)

原文:https://www.cnblogs.com/ccvv/p/12445915.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!