I'm implementing Quicksort algorithm, and I'm getting a "core dumped" error.
However, when I change the arguments for the quickSort()
function to int
instead of size_t
, it works fine. What is the problem?
The code is as follows:
size_t partition(std::vector<int>& numbers, size_t start, size_t end)
{
size_t pivot {end};
size_t actual {start};
for(size_t i{start}; i < end; i++){
if(numbers.at(i) < numbers.at(pivot)){
std::swap(numbers.at(i), numbers.at(actual));
++actual;
}
}
std::swap(numbers.at(actual), numbers.at(pivot));
return actual;
}
Here is the issue:
void quicksort(std::vector<int>& numbers, size_t start, size_t end)
{
if(end > start){
size_t pivot = partition(numbers, start, end);
quicksort(numbers, start, pivot - 1);
quicksort(numbers, pivot + 1, end );
}
}
I know it should be size_t
since I'm working with vector indices, but size_t
doesn't work for this case. Why not?