코딩테스트 연습 스터디 진행중 입니다. ✍✍✍
Notion : https://www.notion.so/1c911ca6572e4513bd8ed091aa508d67
문제
https://www.acmicpc.net/problem/2750
[나의 풀이]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
// 삽입 정렬 활용
static void insertSort(int[] arr, int N) {
for (int i = 1; i < N; i++) {
if (arr[i - 1] > arr[i]) {
for (int j = 0; j <= i - 1; j++) {
if (arr[j] > arr[i]) {
swap(arr, i, j);
}
}
}
}
}
// swap
static void swap(int[] arr, int a, int b) {
int temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int [] arr = new int [N];
for(int i=0;i<N;i++){
arr[i] = Integer.parseInt(br.readLine());
}
insertSort(arr, arr.length);
for(int i=0;i<N;i++){
System.out.println(arr[i]);
}
}
}
정렬 문제입니다! 메서드 활용하지 않고 삽입 정렬 구현해서 풀었습니다!
감사합니다!🐳🐳🐳
👍