/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int divide(int* stock,int head,int tail){
int t=stock[head];
while(head<tail){
while(head<tail && stock[tail] >t) tail--;
if(head<tail) stock[head++]=stock[tail];
while(head<tail && stock[head] <t ) head++;
if(head<tail) stock[tail--]=stock[head];
}
stock[head]=t;
return head;
}
void quicksort(int* stock,int head,int tail){
if(head>=tail) return ;
int t=divide(stock,head,tail);
quicksort(stock,head,t-1);
quicksort(stock,t+1,tail);
}
int* inventoryManagement(int* stock, int stockSize, int cnt, int* returnSize) {
*returnSize=cnt;
int* array=(int*)malloc(sizeof(int)*cnt);
quicksort(stock,0,stockSize-1);
for(int i=0;i<cnt;i++) array[i]=stock[i];
return array;
}
标签:head,LCR,159,quicksort,cnt,int,tail,IIIc,stock From: https://www.cnblogs.com/llllmz/p/18085638