1 #include < stdio.h > 2 void Soft( int * a, int n) 3 { 4 int left,right; 5 int tem; 6 left = 1 ; 7 right = n - 1 ; 8 while (left < right) 9 { 10 for ( int i = right;i >= left;i -- ) 11 { 12 if (a[i] < a[i - 1 ]) 13 {tem = a[i]; 14 a[i] = a[i - 1 ]; 15 a[i - 1 ] = tem; 16 } 17 18 19 } 20 for ( i = left;i <= right;i ++ ) 21 { 22 if (a[i] < a[i - 1 ]) 23 {tem = a[i]; 24 a[i] = a[i - 1 ]; 25 a[i - 1 ] = tem; 26 } 27 28 29 } 30 left ++ ; 31 right -- ; 32 33 34 35 } 36 37 38 } 39 void main() 40 { 41 int a[ 6 ] = { 2 , 5 , 1 , 8 , 3 , 7 }; 42 Soft(a, 6 ); 43 for ( int i = 0 ;i < 6 ;i ++ ) 44 printf( " %2d " ,a[i]); 45 46 }