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

  • 相关阅读:
    TCP通过哪些措施,保证传输可靠
    http协议---简述
    单播、广播、组播、多播
    axios 设置超时时间 timeout
    axios 处理并发请求
    vue 模板语法
    vue keep-alive
    v-if 条件渲染分组
    debounce 防抖动函数
    vue scoped 深度作用选择器
  • 原文地址:https://www.cnblogs.com/sunfuyou/p/5900859.html
Copyright © 2011-2022 走看看