初步实现(不知道对不对😭

This commit is contained in:
2024-11-20 21:48:13 +08:00
parent 882c36c956
commit cca9948fea
3 changed files with 64 additions and 0 deletions
+25
View File
@@ -1 +1,26 @@
#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);
}