c oc swift的冒泡排序

   关于  C 语音的冒泡排序

<span style="color:#000000;">    <span style="font-size:18px;color:#009900;"><span style="font-size:18px;color:#009900;"></span></span></span><pre name="code" class="objc">    //对一个数组排序
int array[10]={2,8,5,4,6,7,9,0,6,3}; for (int i = 0; i<10; i++) { for (int j = 0; j< 9; j++) { if (array[j]>array[j+1]) { int temp = 0; temp = array[j]; array[j] = array[j+1]; array[j+1] = temp; } } } for (int i = 0; i<10; i++) printf("%d\n",array[i]); };



 

  关于 OC 语音的冒泡排序

    <span style="color:#000000;">//对一个数组排序
    NSMutableArray *array = [[NSMutableArray alloc]init];
    for (int i = 0;i<[array count]; i++) {
    for (int j = 0; j< [array count] - 1; j++) {
    if ([array[j] integerValue] > [array[j+1] integerValue]) {
    int a = [[array objectAtIndex:i] intValue];
    int b = [[array objectAtIndex:j] intValue];
    if (a>b) {
    [array replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%d",b]];
    [array replaceObjectAtIndex:j withObject:[NSString stringWithFormat:@"%d",a]];
    }
    }
    }
    for (int i = 0; i<[array count]; i++)
    NSLog(@"%@",[array objectAtIndex:i]);
     }</span>

  关于  Swift  语音的冒泡排序


<span style="font-size:18px;">var array = [2,8,5,4,6,7,9,0,6,3]
         for var i = 0; i < array.count - 1; ++i {
                 for var j = 0; j < array.count - 1 - i; ++j{
                         if array[j] > array[j + 1] {
                                 let temp = array[j + 1]
                                 array[j + 1] = array[j]
                                 array[j] = temp
                       }
                  }
             }
         print("排序后的值:")
         for item in array
         {
                let a = item
                 print(a)
             }</span>

阅读更多
个人分类: 代码段 Code
上一篇瀑布流
下一篇关于 Xcode7网络请求的Http 协议改为 Https 协议的程序修改
想对作者说点什么? 我来说一句

swift oc monkey

2018年06月13日 529KB 下载

没有更多推荐了,返回首页

关闭
关闭