3
我正在使用Fibonacci堆(boost)來排序元素數組,但是我無法遍歷堆。 的代碼是這樣的:如何迭代通過包含deque的斐波那契堆(boost)<MyData>元素
#include <deque>
#include <boost/heap/fibonacci_heap.hpp>
#include <iostream>
struct MyData {
...
long int id;
...
};
struct MyCompare{
bool operator()(const deque<MyData> &a, const deque<MyData> &b) const
{
return a[a.size()-1].id > b[b.size()-1].id;
}
};
int main()
{ deque<MyData> array1;
deque<MyData> array2;
MyData app;
app.id=15;
array1.push_front(app);
app.id=10;
array1.push_front(app);
app.id=5;
array2.push_front(app);
app.id=2;
array2.push_front(app);
boost::heap::fibonacci_heap<deque<MyData>, boost::heap::compare<MyCompare> > fib_heap;
fib_heap.push(array1);
fib_heap.push(array2);
boost::heap::fibonacci_heap<deque<MyData>, boost::heap::compare<MyCompare> >::iterator it;
boost::heap::fibonacci_heap<deque<MyData>, boost::heap::compare<MyCompare> >::iterator beg =fib_heap.begin();
boost::heap::fibonacci_heap<deque<MyData>, boost::heap::compare<MyCompare> >::iterator end =fib_heap.end();
for (it=beg;it!=end; ++it) {
deque<MyData> elem;
elem =*it;
for (int k=0;k < elem.size();k++)
cout<<" "<<elem[k].id;
cout<<"\n";
}
}
它給我這個錯誤在線 「ELEM = *它」:錯誤recursive_tree_iterator的instantion: recursive_tree_iterator(無效): adaptor_type(0) {}
有沒有辦法做到這一點?或者使用另一個有序的堆而不是斐波那契? 非常感謝。