title: Recursive printing issue in C++
body: <p>I am running into what I believe is a recursive issue which I do not know how to resolve. I am designing a hashed array tree structure and I want to print out the "lowest level" in the hashed array tree. I have an array which keeps track of how many nodes are on each level, and I can calculate the lowest level based on this. Here is the code:</p>
  
  <pre><code>template &lt;typename T&gt;
  ostream &amp;operator &lt;&lt; ( ostream &amp;output, const HashNode&lt;T&gt; &amp;node ){
  if(node.stemNode == 0){
    //leafnode                                                                                                                                                                   
  
    for(int i=0; i &lt; node.numElements; i++){
  
      output &lt;&lt; "\n-------------------------------------------" &lt;&lt; endl;
      output &lt;&lt; "This Node's Level: " &lt;&lt; node.nodeLevel &lt;&lt; endl;
      output &lt;&lt; "\nKey: " &lt;&lt; node.keyArray[i] &lt;&lt; endl;
      output &lt;&lt; "\nData: " &lt;&lt; *(node.dataArray[i])  &lt;&lt; endl;
    }
  
  }else if (node.stemNode == 1) {
    //stem node                                                                                                                                                                   
  
    for(int j=0; j&lt;5; j++){
      if(node.childArray[j] != NULL){
        output &lt;&lt; *(node.childArray[j]);
      }
    }
  
  }
  int ctr = 0;
  for(int i=8; i&gt;=0; i--){
    if(levels[i] == 0){
      ctr++;
    }
  }
  int lowest = 9-(ctr+1);
  //output &lt;&lt; "\nLowest Number of Levels: " &lt;&lt; 9-(ctr+1) &lt;&lt; endl;                                                                                                                 
  
  return output &lt;&lt; "\n\nLowest Level: " &lt;&lt; lowest &lt;&lt; " " &lt;&lt; ctr2 &lt;&lt; endl;
  }
  </code></pre>
  
  <p>What happens is that when I print out output, the phrase "Lowest Level" will print out multiple times. I believe this occurs because I traverse my tree recursively. I tried to overcome this by just saving the "lowest level" value to a variable as shown above, but this did not solve the problem. The line continues to print multiple times. Is there a way to overcome this?</p>