Monday, July 27, 2009

Consider the following class definition for a binary tree of integers.?

Consider the following class definition for a binary tree of integers.


class binTree {


public:


btnode* root; // root of the bintree


btnode* current; // current node in the bintree


binTree();


bool isEmpty();


int CountInterior(); //count the number of interior nodes


};


class btnode {


friend binTree;


int value;


binTree left; // left subtree


binTree right; // right subtree





public:


btnode(int value); // Constructor


bool isLeaf(); // True if this node is a leaf; false otherwise


};





Complete the C++ code for a recursive method called CountInterior that returns the number of interior (non-leaf) nodes in a binary tree.





int bintree::CountInterior()


{


}

Consider the following class definition for a binary tree of integers.?
Okay, I considered it. Now what? Seriously, this looks like homework to me, and easy homework at that. The given code lays out a way to test for leaves so all you need to do is use it in a loop and increment a counter if appropriate. The most difficult thing here is setting up a loop to walk the WHOLE tree. That's about all the help I'll give you.

surveys

No comments:

Post a Comment