level 1
酒瘾真劲
楼主
void sortArray(int[] array){
int bottom = XXXXX ;
int top =XXXXX ;
while(XXXXX) {
shiftDown(array, XX, XX);
XXXXX;
}
while(XXXXX) {
int tmp = array[0];
array[0] = array[top-1];
array[top-1] = tmp;
XXXXX;
shiftDown(array, XXX, XXX);
}
}
void shiftDown(int[] array, int top, int bottom){
int i = 2* bottom;
while( i <= top ) {
if( i < top && array[(i+1)-1]> array[i-1]) {
i++;
}
if( array[bottom-1] >=array[i-1] ) {
break ;
}
int tmp = array[bottom-1];
array[bottom-1] = array[i-1];
array[i-1] = tmp;
bottom =i ;
i = 2 * bottom;
}
}
2015年07月29日 20点07分
1
int bottom = XXXXX ;
int top =XXXXX ;
while(XXXXX) {
shiftDown(array, XX, XX);
XXXXX;
}
while(XXXXX) {
int tmp = array[0];
array[0] = array[top-1];
array[top-1] = tmp;
XXXXX;
shiftDown(array, XXX, XXX);
}
}
void shiftDown(int[] array, int top, int bottom){
int i = 2* bottom;
while( i <= top ) {
if( i < top && array[(i+1)-1]> array[i-1]) {
i++;
}
if( array[bottom-1] >=array[i-1] ) {
break ;
}
int tmp = array[bottom-1];
array[bottom-1] = array[i-1];
array[i-1] = tmp;
bottom =i ;
i = 2 * bottom;
}
}