今天去面试被坑了,然后这个发一下吧。
NSMutableArray * array = [NSMutableArray arrayWithObjects: @"1",@"8",@"2",@"7",@"2",@"5",@"9",nil];
//选择
for (int i =0; i<[array count]-1; i++) {
for (int j = i+1; j<[array count]; j++) {
if ([array[i] intValue]>[array[j] intValue]) {
//交换
[array exchangeObjectAtIndex:i withObjectAtIndex:j];
}
}
}
NSLog(@"%@",array);
网友评论