关于两个数组排序方法比较的疑问
本帖最后由 happysxm 于 2013-08-16 13:18:30 编辑
设计了个程序,要对两个数组排序计时,st1有数字出来,st3却总显示0,搞不懂了,请哪位指教!
程序如下:
class compare
{
void Main(string[] args)
{
GC.Collect();
GC.WaitForPendingFinalizers();
int[] myarray = new int[10000];
int[] array2 = new int[10000];
Random myrandom = new Random();
for (int i = 0; i < 10000; i++)
{
myarray[i] = myrandom.Next(99999);
}
for (int i = 0; i < 10000; i++)
{
array2[i] = myrandom.Next(99999);
}
Array.Reverse(array2);
Stopwatch st1 = new Stopwatch();
Stopwatch st3 = new Stopwatch();
st1.Start();
Array.Sort(myarray);
st1.Stop();
st3.Start();
Boolean[] test3 = new Boolean[99999];
for (int i = 0; i < array2.Length; i++)
{
test3[array2[i]] = true;
}
ArrayList newlist = new ArrayList(10000);
for (int i = 0; i < test3.Length; i++)
{
if (test3[i] == true)
newlist.Add(i);
}