向量堆排序

Heap Sorting With Vectors

本文关键字:堆排序 向量      更新时间:2023-10-16

我有一个结构体:

struct incorrect
{
    unsigned short question;
    unsigned short answerChoice;
}

和堆排序函数:

template <typename iterator>
void heapSort(iterator begin,iterator end)
{
    make_heap(begin,end);
    sort_heap(begin,end);
}

和一个函数来合并问题的向量的结构"不正确"。我面临的问题是,当我尝试使用以下语法对结构为"不正确"的向量进行排序时:

heapSort(omitKey1.question.begin(),omitKey1.question.end());

我收到错误,问题不是不正确的成员。我该如何解决这个问题?(我也试过移除"。问题(但这似乎没有帮助)

我想你有一些像

vector<struct incorrect>omitKey1

所以,使用sort(omitKey1.begin(),omitKey1.end(),compare);

return structure1.question < structure2.question

比较使用

同样,这只是排序vector,而不是heap,所以我可能没有排序堆的答案。

同时看看http://www.cplusplus.com/reference/algorithm/sort_heap/