Skip to content

Refactor classes to declarative agree  #3068

@Frankynz

Description

@Frankynz

i suggest to refactor classes to declarative agree for java.

example in BitonicSort.java we have:

void compAndSwap(int a[], int i, int j, int dir) {
    if ((a[i] > a[j] && dir == 1) || (a[i] < a[j] && dir == 0)) {
        // Swapping elements
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}

i suggest: (beacuse this is more readable)

static void compareAndSwap(int[] array, int i, int j, int dir) {
    if ((array[i] > array[j] && dir == 1) || (array[i] < array[j] && dir == 0)) {
        // Swapping elements
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
}

and i suggest to declarative comments to java docs like that 
    /**
 * The parameter dir indicates the sorting direction,
 * ASCENDING or DESCENDING; if (array[i] > array[j]) agrees
 * with the direction, then array[i] and array[j] are
 * interchanged.
 */

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions