算法导论9.3.3

#include 
#define swap(a,b) (a)^=(b);(b)^=(a);(a)^=(b);
using namespace std;
void output(int * input, int p, int size){
    for(int i = p ; i < size; i++){
        cout<<" "<= p; k--) {
            if(A[k] > insert) {
                A[k+1] = A[k];
            } else {
                break;
            }
        }
        
        A[k+1] = insert;
        j++;
    }
    output(A, p, r);
    int mid = (r-1-p)/2;
    return A[p+mid];
}

int partition(int* A, int p, int r, int kv) {
    int main = r-1;
    
    for(int i = p; i < r; i++) {
        if(A[i]==kv) {
            main = i;
        }
    }
    cout << "main: "< 0) {    //    处理余数部分
        midValue[i] = sort(A, p+i*5, r);    
    }
    output(A, p, r);
    output(midValue, 0, groups+1);
    
    int middestValue = sort(midValue, 0, sizeof(midValue)/sizeof(int));
    cout << "middestValue: " << middestValue<< endl;
    int q = partition(A, p, r, middestValue);
    int num = q - p + 1;
    cout<<"q:"< k) {
        return kselect(A, p, q-1, k);
    } else {
        return kselect(A, q+1, r, k-num);
    }
    return 0;
}

int main()
{
   cout << "Hello World"<< endl;
    int input[] = {1,3,2,10,5,11, 12, 8 ,6, 7};
    //sort(input, 0, 10);
    int mid = kselect(input, 0, sizeof(input)/sizeof(int), 8);
    cout <<"ret:"<< mid;
   return 0;
}

你可能感兴趣的:(程序员)