The idea of odd-even ordering is to repeat the two-pass scan in the array. The first scan selects all data item pairs, A[j] and a[j+1],j are odd (J=1, 3, 5 ...). If the values of their keywords are reversed, they are exchanged. The second scan makes the same operation for all even-numbered data items (j=2, 4,6 ...). Repeat this two-pass order until the array is all in order.
Public Static voidOddevensort (int[] arr) { intLen =arr.length; intGroupnumber = (int) Math.ceil (Double) LEN/2); Booleanfinish =false; while(!finish) {Finish=true; for(inti=0; i< Groupnumber; i++){ intK = i*2; if(K < len-1 && Arr[k] > arr[k+1]) {swap (arr, K, K+1); Finish=false; } } for(inti=0; i< Groupnumber; i++){ intK = i*2 + 1; if(K < len-1 && Arr[k] > arr[k+1]) {swap (arr, K, K+1); Finish=false; } } } } Public Static voidSwapint[] arr,intI1,intI2) { if(Arr[i1] >Arr[i2]) { inttemp =Arr[i2]; ARR[I2]=ARR[I1]; ARR[I1]=temp; } }
Parity ordering Java parity sort algorithm for sorting algorithm