对于C#最好的排序算法/ .NET在不同的场景最好的、算法、场景、不同

2023-09-04 01:32:51 作者:触不可及

什么是在C#中排序数据的最佳算法?

What are the best algorithms for sorting data in C#?

有一个分类算法,可以处理80%的种类呢?

Is there one sorting algorithm that can handle 80% of sorts well?

请给code的例子,如适用。

Please give code examples if applicable.

推荐答案

看看这个网站: 排序比较有Animtations

Check out this site: Sorting Comparisons with Animtations

简短的回答:快速排序

更长的答案: 上述网站会告诉你每种算法与一些漂亮的动画的长处和短处。

Longer answer: The above site will show you the strengths and weaknesses of each algorithm with some nifty animations.

简短的回答是没有最好四周排序(但你知道,因为你说80%的时间:)),但快速排序(或3路快速排序)可能会是你可以用最好的通用算法。

The short answer is there is no best all around sort (but you knew that since you said 80% of the time :) ) but QuickSort (or 3 Way Quick Sort) will probably be the best general algorithm you could use.

这是在.net列表中默认使用的算法,这样你就可以叫 .Sort 如果你有什么已经在列表中。

It is the algorithm used by default for Lists in .Net, so you can just call .Sort if what you have is already in a list.

还有我指着你,如果你想了解如何实现这个上面的网站上伪code。

There is pseudo-code on the website I pointed you to above if you want to see how to implement this.