Project #7412 - Binary tree

 Using the tree program, write a program to input twelve FLOATS into a tree. 

The program should print out the inorder, preorder and postorder traversals for the tree indicating the LEVEL of each node as it is printed out. 

In addition to that there should be statements indicating :

 

The number of leaves in the tree

The number of nodes with only one child

The number of nodes with two children

The maximum and minimum leaf levels

 

For Example…if you entered the values

45.5

3.7

66

7.9

8

99.2

23

11

44.5

55

6.2

2.1

88

9

0

32

14

103

92.7

57

 

The tree program I gave you would print out that the root is 45, that 3 is the left of 45,

66 is the right of 45, etc etc…

 

It would then do the inorder traversal:

0 (level 3)

2.1(level2)

3.7 (level1)

6.2 (level 3)

etc 

 

Then you would say: (not necessarily correct)

There are 8 leaf nodes

There are 4 nodes with one child

There are 7 nodes with two children

Maximum leaf level = 6

Maximum leaf level = 3

The strcture has to follow below :

#include <iostream>

using namespace std;

 

const int nil = 0;

class treenode_type    // declaration of class//

{

public:// Tree node type//

int info;

treenode_type *left;

treenode_type *right;

};

 

void setleft(int x);

void setright(int x);

void inorder(treenode_type *p);

treenode_type *p,*q,*root;

int number;

 

void setleft(int x)   // Sets node to left //

{

treenode_type *q;

q = new treenode_type;

(*q).info = x;

(*q).left = nil;

(*q).right = nil;

(*p).left = q;

}

void setright(int x)

{

treenode_type *q;

q = new treenode_type;

(*q).info = x;

(*q).left = nil;

(*q).right = nil;             

(*p).right = q;

}

void inorder(treenode_type *r)

{

  if (r != nil)

{

inorder((*r).left);

cout << (*r).info << "\n";

inorder((*r).right);

}

}

Subject Computer
Due By (Pacific Time) 06/19/2013 12:00 am
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy