-
Notifications
You must be signed in to change notification settings - Fork 20.8k
Closed
Description
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
Labels
No labels