快速稳定的排序算法实现在javascript [英] Fast stable sorting algorithm implementation in javascript

查看:110
本文介绍了快速稳定的排序算法实现在javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在找排序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.

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

这篇关于快速稳定的排序算法实现在javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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