배열2 Day 12-3. Q. 선택정렬 import java.util.Arrays; public class SelectArray { public static void main(String[] args) { int[] arr = {40, 50, 30, 10, 20}; int tmp = 0; for(int i = 0; i arr[j]) { tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; } } System.out.println(Arrays.toString(arr)); } } } 2022. 1. 18. Day 12-2. Q. 삽입정렬 import java.util.Arrays; public class InsertArray { public static void main(String[] args) { int[] arr = {40, 50, 30, 10, 20}; for(int i = 1; i = 0; j--) { // 선택 정렬 if(arr[j] > arr[idx]) { int tmp = arr[j]; arr[j] = arr[idx]; arr[idx] = tmp; } else break; idx--; System.out.println(Arrays.toString(arr)); } } } } 2022. 1. 18. 이전 1 다음