最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

SEO心得admin61浏览0评论
本文介绍了快速稳定的排序算法实现在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.

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

发布评论

评论列表(0)

  1. 暂无评论