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