简体   繁体   中英

Why is a container parameter used in a priority queue for overloading?

std::priority_queue< int, std::vector<int>, std::greater<int> > pq;

为什么使用向量参数?

  • The priority queue implementation can use different types of containers to build the underlining data structure. You can specify which one you like the most using that template parameter.

  • Quoting from here

    Container - The type of the underlying container to use to store the elements. The container must satisfy the requirements of SequenceContainer, and its iterators must satisfy the requirements of RandomAccessIterator. Additionally, it must provide the following functions with the usual semantics: front() push_back() pop_back() The standard containers std::vector and std::deque satisfy these requirements.

Btw, vector is the default one.

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