티스토리 뷰


package cbnu;


public class Select {


public static void main(String[] args) {

// TODO Auto-generated method stub


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


for (int i = 0; i < array.length - 1; i++) {

for (int j = i+1; j < array.length; j++) {

if (array[i] > array[j])

swap(array, i, j);

}

}


for (int i = 0; i < array.length; i++) {

System.out.print(" " + array[i]);

}

}


private static void swap(int[] array, int i, int j) {

// TODO Auto-generated method stub

int temp = array[i];

array[i] = array[j];

array[j] = temp;

}


}





댓글
댓글쓰기 폼