티스토리 뷰


package cbnu;

public class Bubble {

public static void main(String[] args) {
// TODO Auto-generated method stub

int array[] = { 1024, 512, 16, 8, 256, 64, 2048, 9048, 4096, 2 };

for (int i = 0; i < array.length - 1; i++) {
for (int j = 0; j < array.length - i - 1; j++) {
if (array[j] > array[j + 1]) {
swap(array, j, j + 1);
}
}
}
for (int i = 0; i < array.length; i++) {
System.out.print(" " + array[i]);
}
}

private static void swap(int[] array, int i, int index) {
// TODO Auto-generated method stub
int temp = array[i];
array[i] = array[index];
array[index] = temp;
}
}



댓글
댓글쓰기 폼