Вопрос по sorting, objective-c, ios – Используются ли алгоритмы сортировки в NSArray стабильными сортировками?

11

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded Titouan de Bailleul
Error: User Rate Limit ExceededisError: User Rate Limit Exceeded gnasher729
Error: User Rate Limit Exceeded omz
Error: User Rate Limit Exceeded Titouan de Bailleul

Ваш Ответ

3   ответа
4

Error: User Rate Limit Exceeded
Error: User Rate Limit ExceededdoesError: User Rate Limit ExceededNSSortOptions: developer.apple.com/library/ios/#documentation/Cocoa/Reference/…
17

NSSortStable:

NSSortStable

Specifies that the sorted results should return compared items have equal value in the order they occurred originally.

If this option is unspecified equal objects may, or may not, be returned in their original order.

[array sortWithOptions:NSSortStable usingComparator:^NSComparisonResult(id obj1, id obj2) {
    return [obj1 compare:obj2];
}];
(void)sortWithOptions:usingComparator:Error: User Rate Limit Exceeded(NSArray *)sortedArrayWithOptions:usingComparator:Error: User Rate Limit Exceeded
6

The stability of NSArray/NSMutableArray's sorting methods is undefined, so you should anticipate that they are unstable. Being undefined, the situation may also change from release to release, though I don't (myself) anticipate that this is likely. The current implementation uses quick sort, a version of the algorithm nearly identical to BSD's qsort() routine. A bunch of experimentation found at one point that it was hard to do better than that for the general types of data we through at the tests. [Of course, if one has additional information about the data being sorted, one can use other algorithms or modifications which help that case.]

NSArraynot

Похожие вопросы