I’m getting a problem with my display functions dealing with binary search trees. The main problem I’m having is getting the count variable to increment correctly in the recursive function so that I can number the nodes in ascending order.
Would making count a global variable work?
Here is the code for the function:
(p is pointing to the root of the tree, count is initially set to 1)
void displayAscend(nodePtr p, int count)
{
if (p->left != NULL)
displayAscend(p->left, count);
cout << count << ". " << p->acctNum << endl;
count++;
if (p->right != NULL)
displayAscend(p->right, count);
}
Pass the count by reference int&.