This commit is contained in:
ngb
2021-06-07 09:32:52 +02:00
commit 8c99dbafd8
38 changed files with 781 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package algorithms;
public class BetterBubbleSort extends Algorithm {
int border;
public BetterBubbleSort(int[] arr) {
super(arr);
}
@Override
void algorithm() {
border = arr.length;
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length - 1; j++) {
cursor = j;
delay();
if (arr[j] > arr[j + 1]) {
swap(j, j + 1);
accesses += 4;
}
accesses += 2;
comparisons++;
if (j == border - 1) {
break;
}
}
border--;
}
}
}