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);
}
}


em test cái quicksort với 170 file text thì ok (chạy hơi lâu), mỗi file text cỡ 500 từ, mà em sort cỡ 180 file thì nó bị crash lúc đang chạy, debug thì nó bảo stackoverflow, có phải do biến cục bộ nhiều quá không ahnh? em có nên chuyển qua dùng mergesort ko
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?