简体   繁体   中英

std::priority_queue<int, std::vector<int>, std::greater<int> > in min_heap function

In the line below vector is used in the parameter list

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

  1. what is the purpose of using vector?
  2. is vector utilized making the priority queue?
  3. can we use anything else other than vector?

The std::vector is the underlying container used to implement the priority queue.

You can use any container type, given the following constrains (from http://en.cppreference.com/w/cpp/container/priority_queue ):

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.

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