错误:没有匹配函数可调用`qsort(int [(((unsigned int)((int)n))))'

时间:2019-05-19 08:24:42

标签: c++ sorting quicksort partition

IDE上有两个警告:

  

[警告] :C:\ PROGRA〜2 \ C-FREE〜1 \ mingw \ include \ stdlib.h:367:注意:   候选人是:

void qsort(void*, size_t, size_t, int (*)(const void*,const void*))

  

[警告] D:\ saltpass_c \未命名7.cpp:20:注意:

std::allocator<int> >&)

我的代码:

int par(vector<int>&arr, int low, int high)
{
    int pivot = arr[low];
    while(low < high)
    {
        while(low < high && arr[high] >= pivot)high--;
        arr[low] = arr[high];
        while(low < high && arr[low] <= pivot)low++;
        arr[high] = arr[low];
    }
    arr[low] = pivot;
    return low;
}
int qsort(vector<int>&arr)
{
     int mystack[2000];
     int top = -1;
     mystack[++top] = 0;
     mystack[++top] = arr.size() - 1;
     while(top > 0)
     {
         int high = mystack[top--], low = mystack[top--];
         int middle = par(arr, low, high);
         if(middle+1 < high)
         {
             mystack[++top] = middle+1;
             mystack[++top] = high;
         }
         if(low < middle-1)
         {
             mystack[++top] = low;
             mystack[++top] = middle-1;
         }
     }
 }

为什么会出现这些警告?如何消除这些警告?

0 个答案:

没有答案