关闭

c oc swift的冒泡排序

标签: c语言swift冒泡排序Objective-C
206人阅读 评论(0) 收藏 举报
分类:

   关于  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>

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:13769次
    • 积分:425
    • 等级:
    • 排名:千里之外
    • 原创:30篇
    • 转载:0篇
    • 译文:0篇
    • 评论:5条
    文章分类