遍历二叉树的叶子结点
程序员文章站
2022-05-16 11:25:49
...
递归实现遍历二叉树的所有叶子结点
#include<iostream>
using namespace std;
typedef struct TreeNode *BinTree;
typedef BinTree Position;
struct TreeNode
{
int data;
BinTree left;
BinTree right;
};
void leaves(BinTree bt)
{
if(bt)
{
if(!bt->left&&!bt->right)
cout<<bt->data;
leaves(bt->left);
leaves(bt->right);
}
}