Hello all, let me preface this by saying that YES, this is for a homework assignment. That said, I have already completed 99% of the program and the only thing left is what I am about to ask for help on.
I have a function to display a binary search tree using in-order traversal. The function works fine (as does the rest of the program, but I am having some trouble in limiting the output to 10 numbers per line.
I.E,
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
etc.
The function looks like such
void inOrderDisplay(bstNode *nodeToDisplay)
{
if (nodeToDisplay == NULL) return;
inOrderDisplay(nodeToDisplay->left);
cout << setw(6) << right << nodeToDisplay->integer;
inOrderDisplay(nodeToDisplay->right);
}
Now, what I am trying to achieve, as said above, is 10 numbers per line followed by a newline, then the next 10 numbers, etc.
I have tried various things like having a static int counter inside of the function, I have tried using a standard local variable, I have tried passing in the counter as a parameter (reference). Once inside, I have attempted to use (if counter == 0), if (counter % 10 == 0), or if (counter > 10).
I am really at a loss here and this is the only thing holding up my submission of this program. How do you go about doing something like this inside of a recursive function?
Thanks in advance