그래서 코드는 있지만 내 번호는 정렬되지 않습니다. 내가 빠진 것이 있습니까?코드가 올바르게 정렬되지 않습니다.
내 정렬 코드 등 인쇄와 같은 다른 방법 : 여기
public static int[] swapElement (int [] x, int index1, int index2) {
int t = x[index1];
x[index1] = x[index2];
x[index2] = t;
return x;
}
public static int[] sortArray (int [] x) {
int index = 0;
int i=0;
int[] toSort= new int[x.length];
for(int m=0;m<x.length;m++){
index = indexOfMaxInRange(x);
toSort=swapElement(x,i,index);
i++;
}
return toSort;
}
public static int indexOfMaxInRange (int[] x) {
int max = 0;
int i=0;
int maxLocation = 0;
while(i < x.length) {
if (x[i] > max) {
max = x[i];
maxLocation= i;
}
i++;
}
모든 것이 분명하지 fine_ 노력하고 있습니다 _and을. 디버거를 사용하여 코드가 예상했던 것과 다른 위치에서 작동하는지 확인하십시오. –
'swapElement'는 전달 된'toSort' 인자가 변경 될 때 무효가 될 수 있습니다. –