本文介绍了该程序中的秒表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是C#程序:
http://www.4shared.com/file/xAv2qAbB/SortComparison.html [ ^ ]
它具有计时器,该计时器在排序结束时显示排序时间,但是我需要此程序的秒表来显示从排序开始到结束的时间
是否需要另一个线程?
如果可以的话,用该定时器编辑我的代码
注意:我需要像秒表一样向我展示时间
我需要计时器显示每毫秒的排序时间.
here is a C# Program:
http://www.4shared.com/file/xAv2qAbB/SortComparison.html[^]
It has timer that shows sorting time at the end of sorting,but I need a stopwatch for this program that shows time from when sorting starts until its end
Does it need another thread?
if it is possible edit my code with that timer
Note:I need to show me time each moments like Stopwatch
I need timer shows time of sorting every millisecond
推荐答案
public IList BubbleSort(IList arrayToSort, out long elapsedTime)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
int n = arrayToSort.Count - 1;
for (int i = 0; i < n; i++)
{
for (int j = n; j > i; j--)
{
if (((IComparable)arrayToSort[j - 1]).CompareTo(arrayToSort[j]) > 0)
{
object temp = arrayToSort[j - 1];
arrayToSort[j - 1] = arrayToSort[j];
arrayToSort[j] = temp;
RedrawItem(j);
RedrawItem(j - 1);
RefreshPanel(pnlSamples);
}
Thread.Sleep(speed);
}
}
stopWatch.Stop();
elapsedTime = stopWatch.ElapsedMilliseconds;
return arrayToSort;
}
那么你会这样称呼
then you would call it something like this
long methodTime;
IList myList = BubbleSort(listToSort, out methodTime);
希望这对您有帮助
Hope this helps
这篇关于该程序中的秒表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!