//堆排序
public static int[]heap(int[] nums){
for(int i = nums.length/2 -1;i>=0;i--){
adjust(nums,i,nums.length);
}
for(int i=nums.length-1;i>nums.length -4;i--){
swap(nums,0,i);
adjust(nums,0,i);
}
return nums;
}
public static void adjust(int[] nums, int startindex, int length){
int temp = nums[startindex];
for(int i =2*startindex +1 ;i
if(i
if (nums[i]
nums[startindex] = nums[i];
startindex = i;
}
nums[startindex] = temp;
}
public static void swap(int[] nums,int i,int j){
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
网友评论