指针做参数实现冒泡法排序
void Arr_Ex(int *Arr,int nArr){ for(int i=0; i <nArr - 1;i++){ for(int j =0; j<nArr - i -1; j++){ if( Arr[ j ] > Arr [ j + 1 ] ){
//第一种交换 位运算 Arr [ j] = Arr [ j ] ^Arr [ j + 1]; Arr [ j + 1] = Arr [ j] ^ Arr[ j +1 ]; Arr [ j ] = Arr [ j] ^ Arr[ j +1 ]; //第二种交换 中间变量 int nTem = Arr [ j ]; Arr[ j ] = Arr[j +1]; Arr [ j+1] = nTem; } } } } int main(){
int arr[10] = { 1,2,3,4,5,6,7,8,9,10}; Arr_Ex ( arr , 10 ); return 0; }