please help me to solve problem

Posted by davit-datuashvili on Stack Overflow See other posts from Stack Overflow or by davit-datuashvili
Published on 2010-05-28T16:00:14Z Indexed on 2010/05/28 16:01 UTC
Read the original article Hit count: 130

Filed under:

i have operation on heap fixdown operation below is code

public class HEap{
public static void fixdown(int a[],int k,int n){
 while(2*k<=n){
 int j=2*k;
    if (j<n && a[j]<a[j+1])   j++;
   if (!(a[k]<a[j])) break;
  int t=a[k];
a[k]=a[j];
a[j]=k;
k=j; 

}






}


public  static void main(String[]args){

int a[]=new int[]{12,15,20,29,23,22,17,40,26,35,19,51};

fixdown(a,1,a.length);

 for (int i=0;i<a.length;i++){
 System.out.println(a[i]);
}




}
}

//and result is

12
29
20
40
23
22
17
3
26
35
19
51

i am interested why is 3 in the list?in the array is not

© Stack Overflow or respective owner

Related posts about algorithm