Is there any builtin stable sort routine and swap function in .NET?

孤街醉人 提交于 2019-12-01 20:36:57
Doc Brown

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

Is the sorting algorithm used by .NET's `Array.Sort()` method a stable algorithm?

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

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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!