Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- storage
- 아마존
- 스프링
- rhcsa
- hadoop
- linux
- 하둡
- Redshift
- java
- Amazon
- 설치
- Spring
- 재귀
- 빅데이터
- sort
- data
- big data
- redhat
- 자바
- 스토리지
- docker
- 리눅스
- 레드햇
- 알고리즘
- algorithm
- recursive
- AWS
- 자료구조
- 도커
- Data Structure
Archives
- Today
- Total
Developer MJ
[Java] 삽입 정렬 (Insertion Sort) 본문
삽입 정렬
import java.util.Scanner;
class Solution {
static int input[];
static int num;
static void insertionSort()
{
for (int i = 1; i < num; i++)
{
int temp = input[i];
int j = i - 1;
while ((temp < input[j]) && (j >= 0))
{
input[j + 1] = input[j];
j = j - 1;
}
input[j + 1] = temp;
}
}
static void printResult()
{
int i;
for (i = 0; i < num; ++i)
{
System.out.print(input[i] + " ");
}
System.out.println();
}
public static void main(String arg[]) throws Exception {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int test_case = 1; test_case <= T; test_case++)
{
num = sc.nextInt();
input = new int[num];
for (int i = 0; i < num; i++)
{
input[i] = sc.nextInt();
}
insertionSort();
System.out.print("#" + test_case + " ");
printResult();
}
sc.close();
}
}
'Programming > Code' 카테고리의 다른 글
[Java] 퀵정렬 (Quick Sort) (0) | 2019.04.18 |
---|---|
[Java] 계수정렬(Counting Sort) (0) | 2019.04.18 |
[Java] Queue (0) | 2019.02.13 |
[Java] Stack (0) | 2019.02.13 |
[Java] BlobSize Algorithm 문제 (0) | 2017.10.12 |