Comment detail
比較しないソートの作成 (Nested Flatten)
horiuchiさんの#6648をコピペしてC#のコードに改変しました。
殆ど一緒です。行数まで一致しています。
JavaとC#って似てますよね。
殆ど一緒です。行数まで一致しています。
JavaとC#って似てますよね。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | using System;
public class Sample187 {
public static int[] countingSort(int min, int max, int[] data) {
int[] counter = new int[max - min + 1];
foreach(int i in data) {
counter[i - min]++;
}
int[] result = new int[data.Length];
int index = 0;
for(int i = 0; i < counter.Length; i++) {
for(int count = 0; count < counter[i]; count++) {
result[index++] = i + min;
}
}
return result;
}
public static void Main(String[] args) {
int[] sort = countingSort(-1, 10, new int[] { -1, 9, 4, 8, 9, 6, 3, 9, 5, 2 });
foreach(int i in sort) Console.Write(i + " ");
}
}
|





horiuchi
#6648()
[
Java
]
Rating1/1=1.00
counting sortを実装しました。
Rating1/1=1.00-0+
1 reply [ reply ]