Bubble sort fix (#2809)
This commit is contained in:
parent
71de9142f0
commit
a7282d233b
|
@ -19,11 +19,13 @@ public class BubbleSort {
|
|||
|
||||
void optimizedBubbleSort(Integer[] arr) {
|
||||
int i = 0, n = arr.length;
|
||||
|
||||
boolean swapNeeded = true;
|
||||
while (i < n - 1 && swapNeeded) {
|
||||
swapNeeded = false;
|
||||
for (int j = i + 1; j < n - i; j++) {
|
||||
for (int j = 1; j < n - i; j++) {
|
||||
if (arr[j - 1] > arr[j]) {
|
||||
|
||||
int temp = arr[j - 1];
|
||||
arr[j - 1] = arr[j];
|
||||
arr[j] = temp;
|
||||
|
|
Loading…
Reference in New Issue