Hey guys,
The question on the homework is
"Write a function that returns a count of the nodes that contain a value less than the parameter value."

I was wondering if someone could point me in the right direction maybe with some pseudo code or something of the like. ive got

int lessNodeCount(int value) const
{
	int count = 0;//count for the number of nodes to be updated

Im just confused about whether it should be done recursively or not. I know i have to find the value in the tree, move to the left child and count every node stemming from that left child. Im just not sure how to accomplish that.

I figured out how to count the nodes recursively. Im still not sure how to find the node i want. The contains function only returns a true false value and not the pointer to the node for me to be able to use as node1 in the following code.

int lessNodeCount(int value) const
{
	if(node1 == NULL)
		return 0;
	return lessNodeCount(node1->left) + lessNodeCount(node1->right) + 1;
}

i could modify the contains method of the binary search tree class to return the pointer to the node instead of a true false value so i could perform the recursive statement on that node specifically.

BinaryNode *node1 = sTree.contains(value);
int lessNodeCount(BinaryNode *node1->left) const
{
	if(node1 == NULL)
		return 0;
	return lessNodeCount(node1->left) + lessNodeCount(node1->right) + 1;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.