Question & Answer: , that returns the number of nodes in the binary tree. Add this function to the class binary…..

ch Byron Au if he Lush my should be in a siS PI P Write the dad o the function, nodolounds, that returns the number aneda in the by Add this function to the clas BermuTuoitar Croato a program to tract this function. ) write the dea of ho wochin leaves Court, had talkees apan tierkorporate as a parameter a ports, to Jo rootnode of a hioy tree and returns the num be a leaves in a d Binoy ro. Add this Urciu | The He clocs hisery Trote ond create a program to the Jews (Ohion Writo a , swope ultras , JNod Suare a unction the K1 and stress of a now draw AN No uction to the harpoolipe or clus to feed ODI ate a pogrom the fun this

Write the defn of the function, nodecount, that returns the number of nodes in the binary tree. Add this function to the class binary tree type and create a program to test this function. Write the defn of the function leavescount, that takes as a parameter a pointer to the root node of a binary tree and returns the number of leaves in a binary tree. Add this function to the class binary tree type and create a program to test this function. Write a function, Swapsubtrees, that swaps all of the left and right subtrees of a binary tree type and create a program to test the function.

Expert Answer

 

Let the node structure be

Struct Node {
T data;
Node* left;
Node* right;
}

1.
int countLeafNodes(Node *root) {
if (root == NULL)
return 0;
return countNode(root->right) + countNode(root->left) + 1;
}

2.
int countLeafNodes(Node *root) {
if (root == NULL)
return 0;
if(root -> right == NULL && root->left == NULL)
return 1;
return countLeafNode(root->right) + countLeafNode(root->left);
}

3.

void swapLR(Node *root) {
if (root == NULL)
return;
Node* tmpTree = root->left;
root->left = root->right;
root->right = tmpTree;
swapLR(root->right);
swapLR(root->left);
}

I cannot provide you the test code since the class description is missing 🙁

Still stressed from student homework?
Get quality assistance from academic writers!