title: Java indentation in Level-order Tree print, not binary tree
body: <p>I want to print my non-binary tree with level-order traverse. In the code below I indent every time a new set of children has been added, but somehow I need to remove indentations when I go back in the tree again. Here's how this tree prints:</p>
  
  <pre><code>Root
    Home
      HomeChild1
      HomeChild2
      Documents (should be same level as Home)
        DocumentChild1
        DocumentChild2
        Downloads (should be same level as Home and Documents)
          DownloadsChild1
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>queue.add(o);  //root
          int indent = 0;
          while(!queue.isEmpty(){
  
              for(int i=0; i&lt;indent; i++){
                  print("  ");
              }
  
              Object tempObj = queue.remove(o);
              print(tempObj.value);
  
              if(tempObj.children != null){
                  //Adding all childrens, since its not a binary tree I loop throught all children
                  for(int i=0; i&lt;tempObj.children.length; i++){
                      queue.add(0, tempObj.children[i];
                  }
                  indent++;
              }
          }
  </code></pre>
  
  <p>Here is what I want it to look like</p>
  
  <pre><code>Root
    Home
      HomeChild1
      HomeChild2
    Documents
      DocumentChild1
      DocumentChild2
    Downloads
      DownloadsChild1
  </code></pre>