+(void)bubbleSort:(NSMutableArray *)list{
if (list.count <= 1) {
return;
}
int i, y;
BOOL bFinish = YES; //是否发生数据交换
for (i = 1; i<= [list count] && bFinish; i++) {
bFinish = NO; //每次遍历时,重置标志
//从最后一位开始,依次跟前一位相比,如果较小,则交换位置
//当一次遍历没有任何数据交换时,则说明已经排序完成(bFinish=YES),则不再进行循环
for (y = (int)[list count]-1; y>=i; y--) {
if ([[list objectAtIndex:y] intValue] < [[list objectAtIndex:y-1] intValue]) {
//交换位置
// NSLog(@"%d<->%d",[[array objectAtIndex:y-1] intValue],[[array objectAtIndex:y] intValue]);
[list exchangeObjectAtIndex:y-1 withObjectAtIndex:y];
bFinish = YES; //发生数据交换,则继续进行下一次遍历,直到未发生数据交换或者循环完成为止
// NSLog(@"%@",[array componentsJoinedByString:@" "]);
}
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有