Traverse the leaf nodes of the binary tree

Recursively traverse all the leaf nodes of the binary tree

#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);
	}
}

Guess you like

Origin blog.csdn.net/m0_54621932/article/details/114107000