关于排序稳定的问题 [英] A question about sort stable

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

问题描述

稳定的一种意味着它保持对象的原始顺序。一个

到位是稳定的。有没有人可以解释一下

的排序?

thx。

解决方案

gaoxtwarrior写道:


a sort这是稳定意味着它保持对象的原始顺序。一个

到位是稳定的。有没有人可以解释一下

的排序?



这意味着在排序时不会使用大量额外的存储空间。




" gaoxtwarrior" < ga *** @ cssweb.com.cn在消息中写了


>一个稳定的排序意味着它保留了对象的原始顺序。
到位是稳定的。有没有人可以解释我在
的地方是什么类型?



你的前提是错的。 qsort()是一种排序 - 如果你在排序时打印出

数组,你会看到值在其中上下移动 -

但它不是稳定。如果弗雷德弗雷德弗雷迪和弗雷达都比较等于

,因为你对前四个字母进行了不区分大小写的比较,它们将是有条件的,但是当时是随机顺序的

完成了。稳定的排序保留了相等键的顺序。

您可以使用索引作为平局判断器将qsort转换为稳定排序。


Malcolm McLean在03/29/07 15:28写道:


" gaoxtwarrior" < ga *** @ cssweb.com.cn在消息中写道


>>一个稳定的排序意味着它保留了对象的原始顺序。
到位是稳定的。有没有人可以解释我在
的地方是什么类型?



你的前提是错的。 qsort()是一种排序 - 如果你在排序时打印出

数组,你会看到值在其中上下移动 -

但它不是稳定。如果弗雷德弗雷德弗雷迪和弗雷达都比较等于

,因为你对前四个字母进行了不区分大小写的比较,它们将是有条件的,但是当时是随机顺序的

完成了。稳定排序保留了相等键的顺序。

您可以使用索引作为平局判断器将qsort转换为稳定排序。



为了清楚起见:那就是原始字样。索引,而不是物品在某个随机时刻占据的

指数

在排序期间。


-
Er*********@sun.com


a sort which is stable means it keeps the object''s original order. A sort
which is in place is stable. does anyone can explain me what is sort in
place?
thx.

解决方案

gaoxtwarrior wrote:

a sort which is stable means it keeps the object''s original order. A sort
which is in place is stable. does anyone can explain me what is sort in
place?

It means no significant additional storage is used while sorting.



"gaoxtwarrior" <ga***@cssweb.com.cnwrote in message

>a sort which is stable means it keeps the object''s original order. A sort
which is in place is stable. does anyone can explain me what is sort in
place?

Your premise is wrong. qsort() is an sort in place - if you print out the
array as it is sorting you will see values moving up and down within it -
but it is not stable. If Fred fred freddie and Freda all compare equal
because you are doing a case-insensitive comparision of the first four
letters, they will be contigous but in a random order when the sort
finished. A stable sort preserve the order of equal keys.
You can turn qsort into a stable sort by using the index as a tie breaker.


Malcolm McLean wrote On 03/29/07 15:28,:

"gaoxtwarrior" <ga***@cssweb.com.cnwrote in message

>>a sort which is stable means it keeps the object''s original order. A sort
which is in place is stable. does anyone can explain me what is sort in
place?


Your premise is wrong. qsort() is an sort in place - if you print out the
array as it is sorting you will see values moving up and down within it -
but it is not stable. If Fred fred freddie and Freda all compare equal
because you are doing a case-insensitive comparision of the first four
letters, they will be contigous but in a random order when the sort
finished. A stable sort preserve the order of equal keys.
You can turn qsort into a stable sort by using the index as a tie breaker.

Just to be clear: That''s the "original" index, not the
index that the item happens to occupy at some random moment
during the sort.

--
Er*********@sun.com


这篇关于关于排序稳定的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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