简体   繁体   中英

priority queue with a list container

I'm trying to use a list as the underlying container for a priority queue that is holding datanode objects. It seems to work fine using a vector or deque, but i try to use a list as the underlying container and i try to push something onto the queue i get the error :

Error 3 error C2784: 'unknown-type std::operator -(std::move_iterator<_RanIt> &,const std::move_iterator<_RanIt2> &)' : could not deduce template argument for 'std::move_iterator<_RanIt> &' from 'std::_List_unchecked_iterator>>'

struct datanode{
    int depth;
    int cost;
    const int SIZE = 10;
    int ident[9];   
    int parent;
    datanode(int dep, int id[9], int);
    datanode(int dep, int id[9], int, int);
    datanode(const datanode&);
    datanode(); 
    datanode& datanode::operator=(const datanode&);
};

class NodeComparison
{
  public:
    bool operator() (datanode& da, datanode& db)
    {
        return da.cost > db.cost;
    }
};

int main(){
    std::priority_queue<datanode,list<datanode>, NodeComparison> PQueue;
    int a[10] = {1,2,3,4,5,6,7,8,9,10};
    datanode d(0,a,0);
    PQueue.push(d);
 }

§23.6.4 [priority.queue]/p1:

Any sequence container with random access iterator and supporting operations front() , push_back() and pop_back() can be used to instantiate priority_queue .

std::list doesn't have random access iterators.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM