zoukankan      html  css  js  c++  java
  • iosOC可变数组选择,冒泡排序

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

  • 相关阅读:
    测试文档
    详细文档
    需求规格说明文档
    会议
    软工项目
    分组
    项目名
    google 常用的搜索关键词 (技术相关)
    Kafka 入门和 Spring Boot 集成
    用nginx实现分布式限流
  • 原文地址:https://www.cnblogs.com/sunfuyou/p/5900859.html
Copyright © 2011-2022 走看看