.NET中是否有内置的稳定排序例程?
我知道C ++在“算法”std::sort()
下有一个内置的排序例程。同样,我们有什么东西可以和C#一起使用吗?
此外,.NET中是否有内置交换功能?
答案 0 :(得分:10)
使用" C#stable sort"在谷歌透露这个SO帖子作为最佳结果:
Is the sorting algorithm used by .NET's `Array.Sort()` method a stable algorithm?
所以答案是:Enumerable.OrderBy
是一个稳定的排序函数,不是内置在C#中,而是.NET框架库的一部分。
关于" Swap":我不知道.NET框架中的任何预构建的通用交换函数,但here您在不到10行代码中找到了一个实现:
static void Swap<T>(ref T lhs, ref T rhs) { T temp; temp = lhs; lhs = rhs; rhs = temp; }