taiyang2014

冒泡排序的优化

  //冒泡排序的优化
    
    int array10[] = {9, 7, 3, 8, 4};
    BOOL flag1 = YES;
    for (int i = 0; i < 5 - 1 && flag1; i++) {
        flag = NO;//假设本趟循环没有做交换
        for (int j = 0; j < 5 - 1 - i; j++) {
            if (array10[j] > array10[j + 1]) {
                int temp = array10[j];
                array10[j] = array10[j + 1];
                array10[j + 1] = temp;
                flag1 = YES;//交换就置成YES
            }
        }
    }

 

posted on 2015-02-03 20:00  taiyang2014  阅读(152)  评论(0编辑  收藏  举报

导航