-2
> Bubble `BUUBLE
> Sorting
**SWAPING**
`
import java.util.Random;
public class bubble {
**Initializing**
public static int count1 = 0;
public static int swap = 0;
public static int[][] Bubbles(int[] a) {
int output[] = new int[2];
for (int pass = 0; pass < a.length; pass++) {
for (int i = 0; i < a.length - 1; i++) {
count1++;
if (a[i] > a[i + 1]) {
int temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
swap++;
}
}
}
output[0] = swap;
output[1] = count1;
return new int[][] {
a,
output
};
}
}
Bubble sort **Bubble**
Ich habe Ihren Code auf einem sortierten Array ausgeführt und habe 'swap = 0' ... – alfasin