一、排序算法

NSSortConcurrent 是高效的但不稳定的排序算法,例如:快速排序
NSSortStable 是稳定的排序算法,例如:冒泡排序 插入排序
@"one", @"two", @"four", @"three" 进行排序
如果使用 NSSortStable 正确的结果是 @"one", @"two", @"four", @"three"
如果使用 NSSortConcurrent 正确的结果是 @"one", @"two", @"four", @"three" 或者 @"two", @"one", @"four", @"three"
那么 NSSortStable 这个选项就容易选了.没有特殊要求就使用 NSSortConcurrent 速度快,有特殊要求就使用 NSSortStable。
在一个待排序队列中,A和B相等,且A排在B的前面,而排序之后,A排在了B的后面.这个时候,这种算法是不稳定的.
eg.https://zhidao.baidu.com/question/12622489.html
网友评论