首页 > 移动平台 > 详细

iosOC可变数组选择,冒泡排序

时间:2016-09-23 18:25:25      阅读:233      评论:0      收藏:0      [点我收藏+]

#pragma mark 可变数组的排序

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

        

   

NSMutableArray * array1 =[[NSMutableArray alloc]initWithObjects:@"zhige",@"saozi",@"bge",@"xiaolong",@"xiaomo",@"xiaomi", nil];

  //冒泡

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

iosOC可变数组选择,冒泡排序

原文:http://www.cnblogs.com/sunfuyou/p/5900859.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!