初步实现(不知道对不对😭)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user