「java」Bubble Sortバブルソートアルゴリズムのコード

javaコード:
public class BubbleSort {
public static void bubble(int array[]) {
boolean change = true;
for (int i = 0; i < array.length && change; i++) {
change = false;
for (int j = 0; j < array.length – i – 1; j++) {
if (array[j] > array[j + 1]) {
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
change = true;
}
}
}
for (int i = 0; i < array.length; i++) {
System.out.print(array[i] + " “);
}
System.out.println(“\n");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int array[] = { 58, 42, 35, 77, 55, 24, 35, 98 };
bubble(array);
}
}

Java

Posted by arkgame