分区不编译的快速排序
Quick sort with partition not compiling
我一直试图让这段代码编译,但它似乎不希望分区函数起作用。显然这与数组有关,但我无法弄清楚它是什么。
编辑:我使用的是 std::partition,不是原始的分区函数。
#include <ctime>
#include <string>
#include <algorithm>
#include <array>
#include <iostream>
using namespace std;
const int MAX_SIZE = 10000;
const int MIN_SIZE = 10;
这是快速排序:
//quick sort
void quickSort(int arr[], int first, int last, int size)
{
if(last - first + 1< MIN_SIZE)
{
insertionSort(arr,size);
}
else
{
int pivotIndex = partition(arr, first, last);
quickSort(arr, first, pivotIndex-1,size);
quickSort(arr, pivotIndex+1,last,size);
}
}
这是错误:
error: no matching function for call to 'partition(int*&, int&, int&)'
感谢任何可以解决这个问题的人。除了分区功能之外的所有功能似乎都可以正常工作。
我假设您已经完成 using namespace std;
以上代码。在这种情况下,std::partition
是一种设计用于 STL 容器而非原始 C 样式数组的算法。考虑检查引用(例如,here)。
不幸的是,您需要 find/write 一种适用于原始数组的分区算法,或者从 int arr[]
迁移到 std::vector<int>
。
否则,如果partition
确实是您代码中的另一个函数,请一并提供。
希望对您有所帮助。
我一直试图让这段代码编译,但它似乎不希望分区函数起作用。显然这与数组有关,但我无法弄清楚它是什么。
编辑:我使用的是 std::partition,不是原始的分区函数。
#include <ctime>
#include <string>
#include <algorithm>
#include <array>
#include <iostream>
using namespace std;
const int MAX_SIZE = 10000;
const int MIN_SIZE = 10;
这是快速排序:
//quick sort
void quickSort(int arr[], int first, int last, int size)
{
if(last - first + 1< MIN_SIZE)
{
insertionSort(arr,size);
}
else
{
int pivotIndex = partition(arr, first, last);
quickSort(arr, first, pivotIndex-1,size);
quickSort(arr, pivotIndex+1,last,size);
}
}
这是错误:
error: no matching function for call to 'partition(int*&, int&, int&)'
感谢任何可以解决这个问题的人。除了分区功能之外的所有功能似乎都可以正常工作。
我假设您已经完成 using namespace std;
以上代码。在这种情况下,std::partition
是一种设计用于 STL 容器而非原始 C 样式数组的算法。考虑检查引用(例如,here)。
不幸的是,您需要 find/write 一种适用于原始数组的分区算法,或者从 int arr[]
迁移到 std::vector<int>
。
否则,如果partition
确实是您代码中的另一个函数,请一并提供。
希望对您有所帮助。