public void CountingSort(ref int[] list, int min = 0, int max = 0)
{
if(min == 0 && max == 0)
{
for (int i = 0; i < list.Length; ++i)
{
if (list[i] < min)
{
min = list[i];
}
if (list[i] > max)
{
max = list[i];
}
}
}
if(max >= min)
{
int[] Countinglist = new int[max - min + 1];
for (int n = 0; n < list.Length; ++n)
{
Countinglist[list[n] - min]++;
}
list = new int[list.Length];
int num = 0;
int cn = 0;
while (num < Countinglist.Length)
{
for (int x = Countinglist[num]; x > 0; --x)
{
list[cn] = num + min;
cn++;
}
num++;
}
}
}
CountingSort C#
最新推荐文章于 2024-11-03 22:21:51 发布