あにす #6652(2008/07/03 04:50 GMT) [ C# ] Rating0/0=0.00
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 + " "); } }
Rating0/0=0.00-0+
[ reply ]
あにす
#6652()
[
C#
]
Rating0/0=0.00
殆ど一緒です。行数まで一致しています。
JavaとC#って似てますよね。
Rating0/0=0.00-0+