-
-
Notifications
You must be signed in to change notification settings - Fork 76
Open
Labels
epic: snippetinfo: help wantedExtra attention is neededExtra attention is neededresolution: won't fixThis will not be worked onThis will not be worked ontype: bugSomething isn't workingSomething isn't working
Description
public static void bubbleSort(int[] arr) {
var lastIndex = arr.length - 1;
for(var j = 0; j < lastIndex; j++) {
for(var i = 0; i < lastIndex - j; i++) {
if(arr[i] > arr[i + 1]) {
var tmp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = tmp;
}
}
}
}
The outermost loop can be run at most n-1 times, so the changes are as follows
for(var j = 0; j < lastIndex - 1; j++) {
for(var i = 0; i < lastIndex - j - 1; i++) {
Metadata
Metadata
Assignees
Labels
epic: snippetinfo: help wantedExtra attention is neededExtra attention is neededresolution: won't fixThis will not be worked onThis will not be worked ontype: bugSomething isn't workingSomething isn't working
Projects
Status
Done