NSMutableDictionary를 정렬 된 순서대로 키 : 낮은 값의 키가 먼저 인쇄되는 키와 같은 값으로 인쇄하고 싶습니다.NSMutableDictionary에서 keysSortedByValueUsingComparator 메서드를 사용하는 속도는 무엇입니까
이렇게하려면 아래의 NSDictionary의 keysSortedByValueUsingComparator : 메서드를 사용하고 있습니다.
기본 구현에서 빠른 정렬과 같은 접근 방식을 사용하고 O (N * logN)을 달성하는지 또는 모든 객체를 O (N^2) 복잡도로 이끄는 다른 모든 객체와 비교하는지 아는 사람이 있습니까?
는예 : - 물론 O는 (N 로그 N)
NSMutableDictionary *hashTable = [[NSMutableDictionary alloc] init];
....
code that adds a bunch of Objects to the hashtable dictionary with key = NSString and value = NSNumber object
....
NSArray * sortedKeys = [hashTable keysSortedByValueUsingComparator:^(id _Nonnull obj1, id _Nonnull obj2) {
if ([obj1 integerValue] > [obj2 integerValue])
{
return (NSComparisonResult)NSOrderedDescending;
}
if ([obj1 integerValue] < [obj2 integerValue])
{
return (NSComparisonResult)NSOrderedAscending;
}
return (NSComparisonResult)NSOrderedSame;
}];
for (NSString *nextKey in sortedKeys)
{
NSLog(@"%@: %@",nextKey,hashTable[nextKey]);
}
유일한 관련 질문은 다음과 같습니다. 애플 프로그래머는 바보가 아니며, 버블 정렬을 사용하지 않는 것이 안전하다고 생각한다. – Avi
@Avi '는 내 앱에 충분히 빠릅니다.'어쨌든 사이트에 너무 애매합니다. 우리가 어떻게 알았을까요? –
@Yvette, 내가 왜 투표를 끝내겠다고했는지. – Avi