算法导论,找出无序数组中最中间k个数

#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);
    }
}

void SelectKthNearTheMiddle(int A[],int B[],int p,int r,int k) {
    int width = k/2, mid = (r-p)/2;
    int low = mid - width, high = mid + width;
    if(k%2 > 0) {
        (r-p)%2 == 0 ? high++ : low--;
    }
    cout << "low: "< midIdx) {
        //    B[i-lowIdx -1] =  A[i];
        //}
    }
}

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

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