zoukankan      html  css  js  c++  java
  • 快速排序中BUG int 与 int *

    #include <iostream>
    using namespace std;
    int QKPass(int* , int , int);  //若声明为 int QKPass(int, int, int); 会显示错误

    void QKSort(int a[], int low, int high){
        int pos;
        if(low < high){
            pos = QKPass(a, low, high);
            QKSort(a, low, pos - 1);
            QKSort(a, pos + 1, high);
        }
    }

    int QKPass(int *a, int low, int high){
        int x = a[low];
        while(low < high){
            while(low < high && a[high] >= x)
                high--;
            if(low < high){
                a[low] = a[high];
                low++;
            }
            while(low < high && a[low] <= x)
                low++;
            if(low < high){
                a[high] = a[low];
                high--;
            }
        }
        a[low] = x;
        return low;
    }

    int main(){
        int n, a[100];
        int i, j, t;
        
        cin >> n;
        for(i = 1; i <= n; i++)
            cin >> a[i];
        
        QKSort(a, 1, n);
        
        for(i = 1; i <= n; i++)
            cout << a[i] << " ";
            
        return 0;
        
    }

  • 相关阅读:
    java中Excel导出
    springmvc接收各种参数
    restTemplate使用
    java中io流的操作
    在线Cron表达式生成器
    springBoot实现socketio
    maven的使用
    idea中导入githup项目
    java 单例模式之线程安全的饿汉模式和懒汉模式
    spring定时任务的集中实现
  • 原文地址:https://www.cnblogs.com/zhumengdexiaobai/p/6935046.html
Copyright © 2011-2022 走看看