# 【竞赛】排序算法的最快实现-继续,该怎么处理(3)

www.MyException.Cn  网友分享于：2013-02-28  浏览：22次

Random r = new Random(seed);
for (int i = 0; i < MAX; i++) {
nums[i] = r.nextInt(MAX);
}

------解决方案--------------------
C# code
using System;

namespace ConsoleApplication1

class Program

static int MaxRange = 20080623;
static void Main(string[] args)

Test(10*10000);
Test(100*10000);
Test(1000*10000);

public static void Test(int MAX)
{
int[] nums = new int[MAX];
Random r = new Random(MaxRange);
for (int i = 0; i < MAX; i++)

nums[i] = r.Next(MAX);

long begin = System.DateTime.Now.Ticks;
Sort(nums);
long end = System.DateTime.Now.Ticks;
Console.WriteLine("总共" + MAX/10000 + "万数据，用时" + System.TimeSpan.FromTicks(end - begin).Milliseconds + "豪秒");

public static void Sort(int[] a)

int[] p = new int[MaxRange + 1];
for (int i = 0; i <= MaxRange; i++)

p[i] = 0;

for (int i = 0; i <a.Length; i++)

p[a[i]]++;

for (int i = 0, j = 0; i <= MaxRange; i++)

while (p[i] > 0)

a[j++] = i;
p[i]--;

10万需要187毫秒
100万需要250毫秒
1000万需要984毫秒

------解决方案--------------------

------解决方案--------------------
mark................
------解决方案--------------------
C# code
using System;

namespace ConsoleApplication1

class Program

static int MaxRange = 20080623;
static void Main(string[] args)

Test(10*10000);
Test(100*10000);
Test(1000*10000);

public static void Test(int MAX)
{
int[] nums = new int[MAX];
Random r = new Random(MaxRange);
for (int i = 0; i < MAX; i++)

nums[i] = r.Next(MAX);

long begin = System.DateTime.Now.Ticks;
Sort(nums);
long end = System.DateTime.Now.Ticks;
Console.WriteLine("总共" + MAX/10000 + "万数据，用时" + System.TimeSpan.FromTicks(end - begin).Milliseconds + "豪秒");

public static void Sort(int[] a)