public static void sift(int R[],int low,int high)
{
int i=low;
int j=2*i;
int tmp=R[i];
while(j<=high)
{
if(j<high&&R[j]>R[j+1])
j++;
if(tmp>R[j])
{
R[i]=R[j];
i=j;
j=2*i;
}
else break;
}
R[i]=tmp;
}
public static void heapSort1(int R[],int n)
{
int i;
int tmp;
for(i=n/2;i>=1;i--)
sift(R,i,n);
for(i=n;i>=2;i--)
{
tmp=R[1];
R[1]=R[i];
R[i]=tmp;
sift(R,1,i-1);
}
} |
|