码迷,mamicode.com
首页 > 编程语言 > 详细

OC冒泡排序

时间:2015-05-31 21:24:09      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

    NSMutableArray *p = [[NSMutableArray alloc] initWithObjects:@"3",@"5",@"4",@"1",@"7",@"6",@"4",nil];
    for (int i = 0; i<[p count]; i++)
    {
        for (int j=i+1; j<[p count]; j++)
        {
            int a = [[p objectAtIndex:i] intValue];
            int b = [[p objectAtIndex:j] intValue];
            if (a > b)
            {
                [p replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%d",b]];
                [p replaceObjectAtIndex:j withObject:[NSString stringWithFormat:@"%d",a]];
            }
        }
    }
    for (int i = 0; i<[p count]; i++)
    {
        NSLog(@"%@",[p objectAtIndex:i]);
    }

OC冒泡排序

标签:

原文地址:http://www.cnblogs.com/huangzs/p/4542603.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!