Em đang thử implement quicksort trên 1 vector struct word (word gồm có string và int) thì sau khi chạy nó bị lỗi Vector iterator not dereferencable, có anh chị nào có thể sửa giúp em được ko ạ em vẫn còn newbie với vector
int partition(vector<word> &database, int start, int end) //partition the vector
{
word pivot = database[end];
int pIndex = start;
for (int i = pIndex; i < end; i++)
{
if (database[i].freq > pivot.freq)
{
iter_swap(database.begin() + pIndex, database.begin() + i);
pIndex++;
}
}
iter_swap(database.begin() + pIndex, database.end());
return pIndex;
}
void quickSort(vector<word> &database, int start, int end)
{
if (start < end)
{
int partitionIndex = partition(database, start, end);
quickSort(database, start, partitionIndex - 1);
quickSort(database, partitionIndex + 1, end);
}
}