int arr[] = {192,976,23,56,768,342,132,56,9,4,0,123};
int temp;
int maxIndex ;
for(int j = 0;j<arr.length-1;j++){
maxIndex = 0;
for(int i= 0;i<arr.length-j;i++){
if(arr[maxIndex]<arr[i]){
maxIndex = i;
}
}
if(maxIndex != arr.length-1-j){
temp = arr[maxIndex];
arr[maxIndex] = arr[arr.length-1-j];
arr[arr.length-1-j] = temp;
}
}
for(int i:arr){
System.out.print(i+",");
}
网友评论