티스토리 뷰


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;
}
}



댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함