什么是排序算法是稳定的利益? [英] What is the benefit for a sort algorithm to be stable?

查看:123
本文介绍了什么是排序算法是稳定的利益?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个排序是说,如果它保持同键元素的相对顺序是稳定的。我想我的问题是真的,什么是维持这种相对顺序的好处?有人可以给个例子吗?谢谢你。

A sort is said to be stable if it maintains the relative order of elements with equal keys. I guess my question is really, what is the benefit of maintaining this relative order? Can someone give an example? Thanks.

推荐答案

它可以使您的排序为链,通过多个条件。

It enables your sort to 'chain' through multiple conditions.

假设你有在随机顺序姓和名的表。如果排序的名字,然后按姓氏,稳定的排序算法将确保人使用相同的姓氏是按名字排序。

Say you have a table with first and last names in random order. If you sort by first name, and then by last name, the stable sorting algorithm will ensure people with the same last name are sorted by first name.

例如:

  • ·史密斯,阿尔弗雷德
  • 史密斯,捷思锐

将保证是正确的顺序。

这篇关于什么是排序算法是稳定的利益?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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