6-11 先序输出叶结点
作者:互联网
题目链接:https://pintia.cn/problem-sets/15/problems/925
代码:
void PreorderPrintLeaves( BinTree BT ){ if(BT==NULL){ return; } if(BT->Left!=NULL){ PreorderPrintLeaves(BT->Left); } if(BT->Left==NULL&&BT->Right==NULL){ printf(" %c",BT->Data); } if(BT->Right!=NULL){ PreorderPrintLeaves(BT->Right); } }
本质还是先序遍历,输出结点前先判断是否是叶子结点。
注意:输出的是BT->Data数据类型为字符,printf输出时类型为%c
标签:11,PreorderPrintLeaves,结点,Right,BT,先序,NULL,Left 来源: https://www.cnblogs.com/yccy/p/16493787.html