NSMutableArray *p = [[NSMutableArray alloc] initWithObjects:@"3",@"5",@"4",@"1",nil];
- (void)sort:(NSMutableArray *)arr
{
for (int i = 0; i < arr.count; i ++) {
for (int j = i + 1; j < arr.count; j ++) {
if ([arr[i] integerValue] > [arr[j] integerValue]) {
int temp = [arr[i] intValue];
arr[i] = arr[j];
arr[j] = [NSNumber numberWithInt:temp];
}
}
}
NSLog(@"选择排序后:%@",arr);
}
网友评论