HeapSort theory?
<p>I am not using HeapSort to sort an array that is already filled, but am using HeapSort as the array is filled.</p>

<p>For a heap where the smallest values are at the top, my understanding was that when you insert a new value to the heap you checked the parent node to see if the new child is larger. If it is you do nothing, if it isn't you check and swap as need up the tree?</p>

<p>Is this not right because my implementation of it is not working at all:</p>

<pre><code>public class HeapSort{
 static int[] numbers = new int[] { 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
 static int[] array = new int[16];

 public static void main(String[] args) {
    for (int i = 1; i &lt; 15; i++) {
        array[i] = numbers[i];
        if (i &gt; 1)
            sort(i);
    }
    for (int i = 1; i &lt; 15; i++) {
        System.out.println(array[i]);
    }
 }

 public static void sort(int i) {
    int parentLocation = i / 2;
    int childLocation = i;

    int parentValue = array[parentLocation];    
    int childValue = array[childLocation];

    if(parentValue &gt; childValue){
        array[parentLocation] = childValue;
        array[childLocation] = parentValue;
    }
    if(parentLocation != 1){
        sort(parentLocation);
    }
  }
}
</code></pre>

<p>TIA</p>

<p>If its anyhelp this is the output when I give it 1-15 backwards:</p>

<pre><code>2
6
3
9
7
5
4
15
12
13
8
14
10
11
</code></pre>

<p>But you all seem as stumped as I am!</p>
