cxfans
9/9/2019 - 12:48 AM

p303-3

p303-3

// p303-3

void Move1(int l[], int n) {
    int low = 0, high = n - 1, t = l[low];
    while (low < high) {
        while (low < high && l[high] % 2 == 0) high--;
        l[low] = l[high];
        while (low < high && l[low] % 2 != 0) low++;
        l[high] = l[low];
    }
    l[low] = t;
}

void Move2(int l[], int len) {
    int i = 0, j = len - 1, t;
    while (i < j) {
        while (i < j && l[j] % 2 == 0) j--;
        while (i < j && l[i] % 2 == 1) i++;
        if (i < j) {
            t = l[i];
            l[i] = l[j];
            l[j] = t;
        }
        j--;
        i++;
    }
}