Question & Answer: 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 A…..

Please create a test program for each question , you can use your imagination to show the functions are working. All the functions and the class should be in same program

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

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

Expert Answer

 

#include <stdio.h>
#include <stdlib.h>

/* A binary tree node has data, pointer to left child
and a pointer to right child */
struct node
{
int data;
struct node* left;
struct node* right;
};

/* Helper function that allocates a new node with the
given data and NULL left and right pointers. */
struct node* newNode(int data)
{
struct node* node = (struct node*)
malloc(sizeof(struct node));
node->data = data;
node->left = NULL;
node->right = NULL;

return(node);
}

/* Computes the number of nodes in a tree. */
int nodeCount(struct node* node)
{
if (node==NULL)
return 0;
else
return(nodeCount(node->left) + 1 + nodeCount(node->right));
}

/* Function to get the count of leaf nodes in a binary tree*/
unsigned int getLeafCount(struct node* node)
{
if(node == NULL)
return 0;
if(node->left == NULL && node->right==NULL)
return 1;
else
return getLeafCount(node->left)+
getLeafCount(node->right);
}

void swap(struct node* node)
{
if (node==NULL)
return;
else
{
struct node* temp;

/* do the subtrees */
swap(node->left);
swap(node->right);

/* swap the pointers in this node */
temp = node->left;
node->left = node->right;
node->right = temp;
}
}

void inOrder(struct node* node)
{
if (node == NULL)
return;

inOrder(node->left);
printf(“%d “, node->data);

inOrder(node->right);
}

/* Driver program to test size function*/
int main()
{
struct node *root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);

printf(“Number of nodes in binary tree is %d”, nodeCount(root));
printf(“Leaf count of the tree is %d”, getLeafCount(root));

printf(“n Inorder traversal of the constructed tree is n”);
inOrder(root);

/* Convert tree to its mirror */
swap(root);

/* Print inorder traversal of the mirror tree */
printf(“n Inorder traversal of the mirror tree is n”);
inOrder(root);

getchar();
return 0;
}

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