Adjust the array order so that the odd digits are preceded by even numbers

Source: Internet
Author: User

 Packagecodingforoffer.question14;/*** Adjust the array order so that the odd digits are in front of even numbers *@authorAdmin **/ Public classReorderoddeven {/*** Classic * idea 1: Follow the quick sort algorithm, a corner mark pointing to the first even start, a corner mark pointing to the new number, swapping when traversing to odd numbers, and adding 1 * to the corner Mark@return      */     Public voidReorderint[] arr) {        intJ=0;  for(inti = 0; i < arr.length; i++) {            if(arr[i]%2==1) {//If It is odd, if it is greater than 0, and so on, if divisible by 3 is exchanged. This kind of common problem, modify the judging conditions can be.                 inttemp=Arr[i]; Arr[i]=Arr[j]; ARR[J]=temp; J++; }        }    }     Public Static voidMain (string[] args) {Reorderoddeven roe=NewReorderoddeven (); int[] arr={3,4,5,2,3,4,5,34,6,743,34,23,432,2,4,5,23423,4};        Roe.reorder (arr);  for(inti = 0; i < arr.length; i++) {System.out.print (Arr[i]+"   "); }    }}

Adjust the array order so that the odd digits are preceded by even numbers

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.