NSMutableArray *arr = @[@1, @3, @2, @0, @9, @8, @7, @5, @6, @4].mutableCopy;
NSInteger count = arr.count;
for (int i = 0; i < count - 1; i++) {
for (int j = i + 1; j < count; j++) {
if ([arr[i] compare:arr[j]] == NSOrderedDescending) {
NSObject *temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
NSLog(@"%@", arr);
NSArray *arr = @[@1, @3, @2, @0, @9, @8, @7, @5, @6, @4];
NSArray *sortedArr = [arr sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
return [obj1 compare:obj2];
}];
NSLog(@"Arr->%@", arr);
NSLog(@"sortedArr->%@", sortedArr);
NSMutableArray *arrM = [NSMutableArray arrayWithArray:arr];
[arrM sortUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
return [obj2 compare:obj1];
}];
NSLog(@"ArrM->%@", arrM);
网友评论