# Heaps

**URL:** <https://forum.kirupa.com/t/heaps/287541>\
**Category:** programming\
**Created:** [May 3, 2009, 10:26am UTC](https://forum.kirupa.com/t/heaps/287541 "2009-05-03T10:26:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gooo](https://avatars.discourse-cdn.com/v4/letter/g/eb8c5e/32.png) [@Gooo](https://forum.kirupa.com/u/Gooo)\
**Post date:** [May 3, 2009, 10:26am UTC](https://forum.kirupa.com/t/heaps/287541/1 "2009-05-03T10:26:00Z")

</div>

Hi

I’m trying to print a 4-heap

This is my code:

```auto
public AnyType printH(AnyType t, int depth)
       {
           if (t != null)
           {   
              for( int i = 1; i < depth; i++ )
              System.out.print( "	" );
              System.out.println(t);
   
              int a = 4 * (indexnode - 1) + 1;
              
              if (a + 4 < array.length-1)
              {
                  printH(array[a + 1], depth+1);
                  indexnode++;
                  printH(array[a + 2], depth+1);
                  indexnode++;
                  printH(array[a + 3], depth+1);
                  indexnode++;
                  printH(array[a + 4], depth+1);
                  indexnode++;
              }
                  return t;
           }
           else
                  System.out.println("Empty heap");
           
           return t;
       }
   
  private int indexnode = 1;

```

And my output:  
1  
Empty heap  
Empty heap  
Empty heap  
Empty heap  
2  
3  
4  
5  
6  
7  
8  
9  
10

The output is supposed to be:  
(indicated with tab where there is supposed to be a tab)  
1  
tab 2  
tab tab 6  
tab tab 7  
tab tab 8  
tab tab 9  
tab 3  
tab tab 10  
tab 4  
tab 5

What am I doing wrong?
