| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 485 人关注过本帖
标题:一个作业,关于SORTING效率比较,哪为大哥来看看....我实在想不出来错哪里,谢 ...
只看楼主 加入收藏
jjj1985
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-10-4
收藏
 问题点数:0 回复次数:2 
一个作业,关于SORTING效率比较,哪为大哥来看看....我实在想不出来错哪里,谢谢

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;


namespace Sorting_Algorithm_Test1
{
class Program
{
private int[] a;
private int[] b;

private DateTime startTime;
private DateTime stopTime;
private bool running = false;

int u = 9999; int l = 1;

private int maxNum = 9999;

public void B()
{
b = new int[65536];

}

public void GetRandomArray(int n)
{
this.a = new int[n];
Random rd = new Random();
for (int i = 0; i < n - 1; i++)
a[i] = rd.Next(maxNum);
//备份生成的ARRAY
B();
Array.Copy(a, b, n);
}

........

//Algorithm1 SelectionSort(A[0…n-1])

public void SortArray(int n)
{
...............
}
}

//Algorithm2 DistributionCounting(A[0..n-1],l,u)
//Sorts an array of integers from a limited range by distribution counting
//Input: An array A [0...n-1] of intergers between l and u(l<=u),Here I define l=1,u=9999;
//Output:Array S[0...n-1] of A’s elements sorted in nondecreasing order


//Implementation of Distribution Counting.

public void SortArray2(int range)
{

int[] S = new int[range];
int[] D = new int[u - l + 1];
for (int i = 0; i <= u - l; i++) D[i] = 0;

// sort

for (int i = 0; i < range; i++) D[this.b[i]]++; //统计频率

for (int i = u - l - 1; i >= 1; i--) D[i] += D[i + 1]; //为分布作准备

for (int i = 0; i < range; i++) S[--D[this.b[i]]] = this.b[i];

b = S;

}

//Timer
.............
}


class Test
{
static void Main()
{
Program aaa = new Program();
StreamWriter SW;
StreamWriter SW2;
SW = File.CreateText("c:\\file1.txt");
SW2 = File.CreateText("c:\\file2.txt");
for (int n = 100; n < 10001; n = n + 100)
{

aaa.GetRandomArray(n);

aaa.Start();
aaa.SortArray(n);
aaa.Stop();

Console.WriteLine("elapsed time in milliseconds: " + aaa.GetElapsedTime());

//elapsed time in milliseconds
SW.Write(aaa.GetElapsedTime());

//use the backup unsorted array

aaa.Start();
aaa.SortArray2(n);
aaa.Stop();
Console.WriteLine("elapsed time in milliseconds: " + aaa.GetElapsedTime());
SW2.Write(aaa.GetElapsedTime());

}
SW.Close();
SW2.Close();
}
}
}

DEBUG没问题,但就是运行不出来
救急,感激不尽...
PS.完整文件在附件里.

FZc1jY2p.rar (20.05 KB) 一个作业,关于SORTING效率比较,哪为大哥来看看....我实在想不出来错哪里,谢谢


[此贴子已经被作者于2006-10-4 13:12:24编辑过]

搜索更多相关主题的帖子: SORTING 作业 效率 
2006-10-04 13:05
dhddna
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2005-9-22
收藏
得分:0 
1EOd7wPv.rar (17.64 KB)

[此贴子已经被作者于2006-10-5 20:08:03编辑过]


要赢就赢得幸福,要输就输给追求!
2006-10-05 20:05
dhddna
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2005-9-22
收藏
得分:0 
虽然不知道你写的什么!
我就给你改个引用:
using System.Collections.Generic;改为using System.Collections.Specialized;
就好使了!

一运行看的我眼都花了!

要赢就赢得幸福,要输就输给追求!
2006-10-05 20:12
快速回复:一个作业,关于SORTING效率比较,哪为大哥来看看....我实在想不出来错哪 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012881 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved