冒泡排序

冒泡排序_第1张图片


用obj-c写一个冒泡排序

for(int i = 0, i < arr.count - 1,i++){

for (int j = 0,j < arr.count - 1 - i;j++){

int a = [[arr objectAtIndex:j]intValue];

int b=[[arr objectAtIndex:j+1]intValue];

if(a < b){

[arr replaceObjectAtIndex:j withObject:[NSString stringWithFormat:@“%d”,b]];

[arr replaceObjectAtIndex:j+1 withObject:[NSString stringWithFormat:@“%d”,a];

}

}

}

你可能感兴趣的:(冒泡排序)