Created
May 31, 2022 06:20
-
-
Save happyduck-git/d8adc1ea2ec1d693ae54e5be67b2b90d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void countingSort(int[] arr) { | |
//arr의 원소로 들어갈 수 있는 수의 범위가 0부터 100까지라고 가정 | |
//범위에 따라 사이즈를 다르게 하면 됨 | |
int[] countArr = new int[101]; | |
//countArr을 이용해 정수가 몇개 들어왔는지 확인하기 | |
for(int i = 0; i < arr.length; i++) { | |
countArr[arr[i]]++; | |
} | |
//counntArr의 인덱스를 배열에 들어있던 정수로서 활용해 하나씩 프린트해주기 | |
for(int j = 0; j < countArr.length; j++) { | |
while (countArr[j] > 0) { | |
System.out.print(j + "\t"); | |
countArr[j]--; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment