Bubble Sort
private static int[] Bubble(int data[]) {
int temp;
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < data.length - 1; j++) {
if (data[j] > data[j + 1]) { //if arr[n] > arr[n+1] , exchange
temp = data[j];
data[j] = data[j + 1];
data[j + 1] = temp;
}
}
Show(data, i);
}
return data;
}
int temp;
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < data.length - 1; j++) {
if (data[j] > data[j + 1]) { //if arr[n] > arr[n+1] , exchange
temp = data[j];
data[j] = data[j + 1];
data[j + 1] = temp;
}
}
Show(data, i);
}
return data;
}
留言
張貼留言