Microsoft如何实现Array.sort()方法?有没有这方面的文件(参考)?对于Visual Basic中的所有类型的Sort(),它是否相同?
这是我想要的一个简单的例子.
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)
在我的原始示例中(排序之前),MyArray(0)= 1并且在排序MyArray(0)= 1之后.
这是相同的原始1或另一个1(添加到阵列的最新的一个)移动到那个位置?
如果排序后MyArray(0)= 1,则在排序之前应该是MyArray(5)= 1.
解决方法
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的OrderBy方法是稳定的. OrderBy in the MSDN的文章指出:
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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。