Parity ordering Java parity sort algorithm for sorting algorithm

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.