Question: #include using namespace std; struct BSTnode { int data; BSTnode * left; BSTnode * right; } ; BSTnode * addNode ( BSTnode * root ,

#include
using namespace std;
struct BSTnode {
int data;
BSTnode *left;
BSTnode *right;
};
BSTnode *addNode(BSTnode *root, int value){
if (root == nullptr){
root = new BSTnode;
root->left = nullptr;
root->right = nullptr;
root->data = value;
return root;
} else if (value < root->data){
root->left = addNode(root->left, value);
return root;
} else if (value > root->data){
root->right = addNode(root->right, value);
return root;
}
return root;
}
int main(){
BSTnode *root = nullptr;
root = addNode(root,1);
root = addNode(root,3);
root = addNode(root,5);
root = addNode(root,8);
root = addNode(root,-11);
root = addNode(root,-15);
root = addNode(root,-10);
}
Provided a Binary Tree with each node with an integer value, write a function called average that will find the average of all of the leaf nodes in a Binary Tree. Remember, leaves are nodes that do not have any children. Feel free to define helper functions to help you with this task. write in C++ please.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!