package com.test.huawei;
public class HeapSort {
public static int heap_size;
//Ë«Ç×±àºÅ
public static int parent(int i){
return i/2;
}
//×óº¢×Ó±àºÅ
public static int leftChild(int i){
return 2*i;
}
//ÓÒº¢×Ó±àºÅ
public static int rightChild(int i){
return 2*i+1;
}
/**
* @param args
*/
//×î´ó¶Ñ
public static void max_heapify(int[] a,int i){
int left=leftChild(i);
int right=rightChild(i);
int largest=0;
if(left<heap_size&&a[i]<a[left]){
largest=left;
}else{
largest=i;
}
if(right<heap_size&&a[right]>a[largest]){
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余2页未读,立即下载