public class MySort {
public static void main(String[] args) {
MySort sort = new MySort();
int[] arr = new int[]{
sort
for(int i : arr){
System
}
}
public void sort(int[] targetArr){//小到大的排序
int temp =
for(int i =
for(int j = i;j<targetArr
if(targetArr[i]>targetArr[j]){
/*//方法一
temp = targetArr[i];
targetArr[i] = targetArr[j];
targetArr[j] = temp;
//方法二:
targetArr[i] = targetArr[i] + targetArr[j];
targetArr[j] = targetArr[i]
targetArr[i] = targetArr[i]
//方法三
targetArr[i] = targetArr[i]^targetArr[j];
targetArr[j] = targetArr[i]^targetArr[j];
targetArr[i] = targetArr[i]^targetArr[j];
}
}
}
}
}
測試
//拿
Java代碼
int a =
a = a + b;//
b = a
a = a
System
//**********************************************************
int c=
int d=
c=c^d;//
System
d=c^d;//
c=c^d;//
System
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25774.html