美文网首页
冒泡排序

冒泡排序

作者: HuLL乐乐 | 来源:发表于2016-09-26 09:56 被阅读5次

冒泡排序(从小到大)
//大字典存放所有数据(33个小字典他们的key是1-33数字)
self.dataDic = dic;

NSMutableArray *array = [[NSMutableArray alloc]initWithArray:[dic allKeys]];

for (int i = 0; i < array.count; i ++)
{
    for ( int j = 0; j < array.count - i -1; j ++)
    {
        if([array[j] intValue] > [array[j+1] intValue])
        {
            
            int temp = [array[j] intValue];

            array[j] = array[j+1];

            array[j+1] = [NSString stringWithFormat:@"%d",temp];
        }
        
    }

}

相关文章

网友评论

      本文标题:冒泡排序

      本文链接:https://www.haomeiwen.com/subject/ficqyttx.html