经典快排

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int divide(int* a,int head,int tail){
    int t=a[head];
    while(head<tail){
        while(head<tail && a[tail] > t) tail--;
        if(head<tail) a[head++]=a[tail];
        while(head<tail && a[head] < t) head++;
        if(head<tail) a[tail--]=a[head];
     }
     a[head]=t;
     return head;
}

void quicksort(int* a,int head,int tail){
    if(head>=tail) return;
    int t=divide(a,head,tail);
    quicksort(a,t+1,tail);
    quicksort(a,head,t-1);
}

int* inventoryManagement(int* stock, int stockSize, int cnt, int* returnSize) {
    *returnSize=cnt;
    int* temp=(int*)malloc(sizeof(int)*cnt);
    quicksort(stock,0,stockSize-1);
    for(int i=0;i<cnt;i++) temp[i]=stock[i];
    return stock;
}

结果: