zoukankan      html  css  js  c++  java
  • iOS(OC)中的冒泡排序

    NSMutableArray *array = [NSMutableArray arrayWithObjects:@"12",@"84", @"35", @"70", @"85", @"99", nil];
            NSInteger count = [array count];
            for (int i = 0; i < count; i++) {
                for (int j = 0; j < count - i - 1; j++) {
                   // if ([[array objectAtIndex:j] intValue] > [[array objectAtIndex:(j + 1)] intValue]) {   //这里在用[array objectAtIndex:j]时候必须intValue
    //                if([[array objectAtIndex:j] compare:[array objectAtIndex:j + 1]] == -1){  //这里整体必须有一个返回值,-1,0,1,因为compare的返回值NSComparisonResult是一个枚举类型的值,所以要返回一个值
                     
                    if([[array objectAtIndex:j] compare:[array objectAtIndex:j + 1] options:NSNumericSearch] == 1){  //同上potions  NSNumericSearch = 64,
                        [array exchangeObjectAtIndex:j withObjectAtIndex:(j + 1)];  //这里可以用exchangeObjectAtIndex:方法来交换两个位置的数组元素。
                    }
                }
            }
            for (NSString *i in array) {
                NSLog(@"%@", i);
            }
             
             
             
            NSMutableArray *array1 = [NSMutableArray arrayWithObjects:@"12",@"84", @"35", @"70", @"85", @"99", nil];
            [array1 sortUsingSelector:@selector(compare:)];
            NSLog(@"%@", array);
             
    
  • 相关阅读:
    redis未授权访问简单总结
    CORS跨域资源共享漏洞初探
    Mysql UDF提权方法
    hacknos-player靶机渗透
    深入理解Java虚拟机-类加载连接和初始化解析
    Dnslog盲注
    让服务器使用密钥
    自动备份站点
    自动放行nginx后台访问ip
    mysql增备
  • 原文地址:https://www.cnblogs.com/ios988/p/5766201.html
Copyright © 2011-2022 走看看