.NET中是否有任何内置的稳定排序例程和交换功能? [英] Is there any builtin stable sort routine and swap function in .NET?

查看:98
本文介绍了.NET中是否有任何内置的稳定排序例程和交换功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.NET中是否有任何内置的稳定排序例程?

Is there any in-built stable sort routine in .NET?

我知道C ++在算法下有一个内置的排序例程 std :: sort()。同样,我们是否可以将某些东西与C#一起使用?

I know that C++ has an in-built sort routine under "algorithms" std::sort(). Likewise, do we have something to use along with C#?

此外,.NET中是否有任何内置的交换功能?

Also, is there any in-built swap function in .NET?

推荐答案

在Google中使用 C#稳定排序显示此SO帖子为最佳结果:

Using "C# stable sort" in Google revealed this SO post as top result:

。NET的Array.Sort()方法使用的排序算法是稳定的算法吗?

所以答案是: Enumerable.OrderBy 是稳定的排序函数,不是C#内置的,

So the answer is: Enumerable.OrderBy is a stable sort function, not built into C#, but part of the .NET framework libraries.

关于交换:我不知道.NET框架中有任何预建的通用交换函数,但是在这里,您会发现不到10个实施代码行:

Concerning "Swap": I don't know of any prebuilt generic swap function in the .NET framework, but here you find an implementation in less than 10 lines of code:


static void Swap<T>(ref T lhs, ref T rhs)
{
    T temp;
    temp = lhs;
    lhs = rhs;
    rhs = temp;
}


这篇关于.NET中是否有任何内置的稳定排序例程和交换功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆