27 lines
449 B
C++
27 lines
449 B
C++
#include "BiTree.h"
|
|
|
|
bool BiTree::is_empty(BiTree *bt) {
|
|
if(bt==nullptr) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool BiTree::is_leaf(BiTree *bt) {
|
|
if(bt->left==nullptr && bt->right==nullptr) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
int BiTree::sum_leaf(BiTree *bt) {
|
|
if(is_empty(bt)) {
|
|
return 0;
|
|
}
|
|
if(is_leaf(bt)) {
|
|
return bt->data;
|
|
}
|
|
return sum_leaf(bt->left)+sum_leaf(bt->right);
|
|
}
|
|
|