???????????Java???
???????????? ???????[ 2014/1/17 9:48:46 ] ????????Java ???????
?????????????Tree Selection Sort??
????????????????????????????????????????任?????????????????????? N ????? ?? ?????????С?? (n+1)/2???????????????????С??[n+1]/4?????????????????????????????????????????
????????????????????С????????С????????????滻?"???"??????????????????
?????????????????????????Java???棺
public static void treeSelectionSort(int[] data) {
if (data == null || data.length <= 1)
return;
int len = data.length ?? low = 0 ?? i ?? j;
// add Auxiliary Space
int[] tmp = new int[2*len -1];
int tSize = tmp.length;
//construct a tree
for(i =len-1 ?? j=tmp.length-1;i >=0 ;i--??j--){
tmp[j]=data[i];
}
for(i = tSize -1 ; i > 0 ; i-=2){
tmp[(i-1)/2] = tmp[i] > tmp[i-1]? tmp[i-1]:tmp[i];
}
//end
//remove the minimum node.
while(low < len){
data[low++] = tmp[0];
for(j=tSize-1;tmp[j]!=tmp[0];j--);
tmp[j] = Integer.MAX_VALUE;
while(j > 0){
if(j%2 == 0){ //?????????
tmp[(j-1)/2] = tmp[j] > tmp[j-1]?tmp[j-1]:tmp[j];
j = (j-1)/2;
}else{ //?????????
tmp[j/2]=tmp[j] > tmp[j+1]? tmp[j+1]:tmp[j];
j = j/2;
}
}
}
}
???????????????????????? N ?????????? ??? 2*N -1 ?????????
????????
while(j > 0){
if(j%2 == 0){ //?????????
tmp[(j-1)/2] = tmp[j] > tmp[j-1]?tmp[j-1]:tmp[j];
j = (j-1)/2;
}else{ //?????????
tmp[j/2]=tmp[j] > tmp[j+1]? tmp[j+1]:tmp[j];
j = j/2;
}
}
?????????????????????е?С???
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11