我有一个结构体:
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());我收到问题不是不正确的成员的错误。我如何解决这个问题?(我也试过删除".question“,但似乎没有帮助)
发布于 2014-03-16 04:06:10
我想你有类似这样的东西
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/
@user3093536 this应该会有帮助。
https://stackoverflow.com/questions/22429000
复制相似问题