是如何的Array.Sort在.NET中实现的? [英] how was Array.Sort implemented in .NET?

查看:350
本文介绍了是如何的Array.Sort在.NET中实现的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的结构,在我的节目,我根据在结构上采用的IComparer 的值进行排序的结构。

I am using structures in my programming and I sort the structure according to a value in the structure using IComparer.

怎么微软实施的Array.Sort()的方法?是否有任何文件(参考)这个?难道是相同的所有类型的排序()在Visual Basic?

How did Microsoft implement the Array.Sort() method? Is there any documentation (references) for this? Is it the same for all types of Sort() in Visual Basic?

这是一个简单的例子是我想要的。

This is a simple example for what I want.

Dim MyArray(6) As Integer
    MyArray(0) = 1
    MyArray(1) = 45
    MyArray(2) = 45
   ' Some Code.....
    '.........
    '..........
    MyArray(3) = 1
    MyArray(4) = 10
    ' Some Code.....
    '.........
    '..........
    MyArray(5) = 1
    MyArray(6) = 57

    Array.Sort(MyArray)

的Array.Sort()将解决这阵为:(1 1 1 10 45 45 57)

如何数1获得排序?难道是带给结束的第一个或保留老在同一个指数?

How does number 1 get sorted? Is it bringing to the end the first one or keeps the old one in the same index?

在我原来的例子(排序前), MYARRAY(0)= 1 和排序后 MYARRAY(0)= 1

In my original example (before sorting), MyArray(0) = 1 and after sorting MyArray(0) = 1.

这是相同的原始1或该另一个1(最新的一个添加到阵列)移动到那个位置?

Is this the same original 1 or this another 1 (the newest one added to the array) moved to that position?

在情况下, MYARRAY(0)= 1 排序后应 MYARRAY(5)= 1 前整理

In case the MyArray(0) = 1 after sorting should be MyArray(5) = 1 before sorting.

推荐答案

的Array.Sort是一种不稳定的排序,所以它们同样是不确定的,而不是保守的元素的顺序。在MSDN上的Array.Sort 文章说:

Array.Sort is an unstable sort, so the order of elements which are the same is undefined and not conserved. The article on Array.Sort in MSDN states:

此方法使用快速排序算法。此实现执行不稳定排序;也就是说,如果两个元素是相等的,它们的顺序可能不是preserved。与此相反,一个稳定的排序preserves中等于元素的顺序

This method uses the QuickSort algorithm. This implementation performs an unstable sort; that is, if two elements are equal, their order might not be preserved. In contrast, a stable sort preserves the order of elements that are equal.

LINQ的另一方面排序依据方法是稳定的。在MSDN 国在排序依据的文章:

LINQ's OrderBy methods on the other hand are stable. The article on OrderBy in the MSDN states:

此方法执行一个稳定的排序;也就是说,如果两个元素的密钥是相同的,该元素的顺序是preserved。相反,不稳定的排序不preserve具有相同键元件的顺序

This method performs a stable sort; that is, if the keys of two elements are equal, the order of the elements is preserved. In contrast, an unstable sort does not preserve the order of elements that have the same key.

这篇关于是如何的Array.Sort在.NET中实现的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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