快速稳定的排序算法实现在javascript算法、稳定、快速、javascript

2023-09-11 01:43:15 作者:萌哒哒的小怪兽

我在找排序200-300对象的数组,在一个特定的密钥和一个给定的顺序(ASC / DESC)排序。结果的顺序必须是一致的,稳定的。

I'm looking to sort an array of about 200-300 objects, sorting on a specific key and a given order (asc/desc). The order of results must be consistent and stable.

什么是使用最好的算法,以及你能提供它的一个例子是在JavaScript实现?

What would be the best algorithm to use, and could you provide an example of it's implementation in javascript?

谢谢!

推荐答案

有可能得到一个稳定的从非稳定排序功能排序。

It is possible to get a stable sorting from a non-stable sort function.

在整理你的所有元素的位置。 在您的排序情况,如果两个元素相等,则排序的位置。

Before sorting you get the position of all the elements. In your sort condition, if both elements are equal, then you sort by the position.

田田!你已经有了一个稳定的排序。

Tada! You've got a stable sort.

我已经在我的博客,如果你想知道更多关于这项技术,以及如何实现它写一个关于它的文章:http://blog.vjeux.com/2010/javascript/javascript-sorting-table.html

I've written an article about it on my blog if you want to know more about this technique and how to implement it: http://blog.vjeux.com/2010/javascript/javascript-sorting-table.html

 
精彩推荐
图片推荐