Answered Essay: 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 c

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<iostream>

using namespace std;

class tree

{

struct TreeNode{

int data;

struct TreeNode *left;

struct TreeNode *right;

};

//new_node and its data and left and right pointers

struct TreeNode *new_node(int item)

{

struct TreeNode *temp=new TreeNode;

// struct TreeNode *temp=(struct TreeNode*)malloc(sizeof(struct TreeNode));

temp->data=item;

temp->left=temp->right=NULL;

return temp;

}

//inserting elements into a tree

struct TreeNode* insert(struct TreeNode *temp,int key)

{

if(temp==NULL)

return new_node(key);

if(key<temp->data)

temp->left=insert(temp->left,key);

else if(key>temp->data)

temp->right=insert(temp->right,key);

return temp;

}

//leaf count

int leavescount(struct TreeNode *root)

{

if(root==NULL)

return 0;

if(root->left==NULL&&root->right==NULL)

return 1;

else

return leavescount(root->left)+leavescount(root->right);

}

//nodes count

int nodecount(struct TreeNode *root)

{

int c=1;

if(root==NULL)

return 0;

else

{

c=c+nodecount(root->left);

c=c+nodecount(root->right);

return c;

}

}

//swap sub tree function

void swapsubtree(struct TreeNode *root)

{

struct TreeNode *temp=NULL;

if(root==NULL)

return;

else

{

swapsubtree(root->left);

swapsubtree(root->right);

}

temp=root->left;

root->left=root->right;

root->right=temp;

}

//inorder function

void inorder(struct TreeNode *root)

{

if(root==NULL)

return;

else

{

inorder(root->left);

cout<<root->data<<” “;

inorder(root->right);

}

}

//main function

int main()

{

int count;

struct TreeNode *root=NULL;

//inserting into binary tree

root=insert(root,3);

insert(root,2);

insert(root,5);

insert(root,6);

insert(root,7);

//calling inorder of the tree

cout<<“nInorder, Before Swaping:n”;

inorder(root);

//after inserting nodes as tree, the tree looks like this

// 3

// 2 5

// 6

// 7

//calling the required function

//calling leavescount to count the no of leaf nodes

count=leavescount(root);

cout<<“nNumber of Leaf nodes:”<<count;

//calling nodecount function to count number of nodes

count=nodecount(root);

cout<<“nNumber of nodes:”<<count;

//calling function to swap subtree nodes

swapsubtree(root);

//calling inorder function after swapping

cout<<“nAfter swaping sub tree:n”;

inorder(root);

}

};

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.

× How can I help you?