public class MySort {
public static void main(String[] args) {
MySort sort = new MySort();
int[] arr = new int[]{};
sortsort(arr);
for(int i : arr){
Systemoutprint(i+);
}
}
public void sort(int[] targetArr){//小到大的排序
int temp = ;
for(int i = ;i<targetArrlength;i++){
for(int j = i;j<targetArrlength;j++){
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[j];
targetArr[i] = targetArr[i] targetArr[j];*/
//方法三
targetArr[i] = targetArr[i]^targetArr[j];
targetArr[j] = targetArr[i]^targetArr[j];
targetArr[i] = targetArr[i]^targetArr[j];
}
}
}
}
}
测试
//拿位来表示吧(正规位)
Java代码
int a = b = ;
a = a + b;//
b = a b;//
a = a b;//=
Systemoutprintln(a+ +b);
//**********************************************************
int c=;//
int d=;//
c=c^d;//
Systemoutprintln(c);
d=c^d;//
c=c^d;//
Systemoutprintln(c+ +d);