ios oc可变数组排序

1.选择排序

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);

2.冒泡

for (int i =0; i<[array1 count]-1; i++) {
for (int j =0; j<[array1 count]-1-i; j++) {
if(([array1[j] compare:array1[j+1]]) == NSOrderedDescending){
//交换
[array1 exchangeObjectAtIndex:j withObjectAtIndex:j+1];
}
}
}

NSLog(@”%@”,array1);