今天爱分享给大家带来IOS开发算法 插入排序 【附代码】,希望能够帮助到大家。
- (void)insertSortArray:(NSMutableArray *)array { for (int i = 1; i < [array count]; i++) { int j = i; NSInteger temp = [[array objectAtIndex:i] integerValue]; while (j > 0 && temp < [[array objectAtIndex:j - 1] integerValue]) { [array replaceObjectAtIndex:j withObject:[array objectAtIndex:(j - 1)]]; j--; } [array replaceObjectAtIndex:j withObject:[NSNumber numberWithInteger:temp]]; } }