Hello, I am trying to implement heap sort using an algorithm, and i was able to write the code, and i think it is correct, but when trying to output it it gives me the same array, for more details check the pic below

this is the code i wrote:

and the result is in the pic below :Code:`import java.util.Arrays;`

public class Heap

{

public static void main (String[] args)

{

int [] a = {7, 4, 3, 1, 2};

buildMaxHeap(a);

}

public static void buildMaxHeap (int[] a)

{

System.out.println(Arrays.toString(a));

int len = a.length;

for (int i = len / 2; i >= 0; i--)

{

maxHeapify(a, i, len);

}

System.out.println(Arrays.toString(a));

}

public static void maxHeapify (int[] a, int i, int n)

{

int largest;

int left = 2 * i;

int right = (2 * i) + 1;

if (left < n && a[left] > a[i])

{

largest = left;

}else{

largest = i;

}

if (right < n && a[right] > a[largest])

{

largest = right;

}

if (largest != i)

{

int temp = a[i];

a[i] = a[largest];

a[largest] = temp;

maxHeapify(a, largest, n);

}

}

}

http://i43.tinypic.com/31293li.png

please can someone tell me where have I gone wrong???

NOTE: the algorithm assumed the array is 1-based indexing