(void)insertSortLess:(NSMutableArray *)array{
int b,c,j;
NSLog(@“a”);
for (int i = 1; i < array.count; i++) {
c = [NSString stringWithFormat:@"%@",array[i]].intValue;
for (j = i; j > 0; j–) {
b = [NSString stringWithFormat:@"%@",array[j-1]].intValue;
if (b > c) {
1 array[i] = array[i];
2// array[j-1] = array[i];
3// array[i] = array[j-1];
}else{
break;
}
}
[array exchangeObjectAtIndex:i withObjectAtIndex:j];
}
NSLog(@" less : %@",array);
}
随机生成测试:
NSMutableArray * array = [NSMutableArray arrayWithCapacity:0];
for (int i = 0; i < 10; i++) {
intger = arc4random()%100000;
[array addObject:[NSNumber numberWithInt:intger]];
}
[InsertSort insertSortLess:array];