并行运算版
package dna;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveAction;
public class SortDNA extends RecursiveAction {
private static int[] arr;
private int begin;
private int end;
private int level;
public SortDNA(int[] arr, int begin, int end, int level) {
this.arr = arr;
this.begin = begin;
this.end = end;
this.level = level;
}
public SortDNA(int begin, int end, int level) {
this.begin = begin;
this.end = end;
this.level = level;
}
@Override
protected void compute() {
if (level >= 0) {
int left = begin, right = end, temp = 0;
uu: while (left <= right) {
// 1.从begin开始往右边找1
temp = arr[left] >> level & 1;
if (temp == 1) {
//2,找到了1
while (left < right) {
// 3.从right开始往左边找0
temp = arr[right] >> level & 1;
if (temp == 0) {
//4,也找到了0
// 5,碱基配对(0,1互换)
temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
right--;
left++;
continue uu;// 生生不息,六九不已
}
right--;