Coding Interviews: Questions, Analysis & Solutions by Harry He

Coding Interviews: Questions, Analysis & Solutions by Harry He

Author:Harry He
Language: eng
Format: epub, pdf
Publisher: ApressĀ®
Published: 2012-12-17T16:00:00+00:00


while(begin < end && criterion.check(nums[end]))

end--;

if(begin < end) {

int temp = nums[begin];

nums[begin] = nums[end];

nums[end] = temp;

}

}

}

In order to place odd numbers before even ones, a specific criterion isEven is defined, as shown in Listing 5-16.

Listing 5-16. Java Code to Reorder Numbers in an Array (Version 2)

void reorderOddEven_solution2(int nums[]) {

Criterion isEven = new Criterion() {

public boolean check(int num) {

if((num & 0x1) == 0)

return true;

return false;

}

};



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.