[問題] C++ STL priority_queue
這是在C++ library 看到對STL裡面 priority_queue的敘述
template < class T, class Container = vector<T>,
class Compare = less<typename Container::value_type> >
class priority_queue;
Where the template parameters have the following meanings:
T: Type of the elements.
Container: Type of the underlying container object used to store and access
the elements.
Compare: Comparison class: A class such that the expression comp(a,b), where
comp is an object of this class and a and b are elements of the container,
returns true if a is to be placed earlier than b in a strict weak ordering
operation. This can either be a class implementing a function call operator
or a pointer to a function. This defaults to less<T>, which returns the same
as applying the less-than operator (a<b).
The priority_queue object uses this expression when an element is inserted or
removed from it (using push or pop, respectively) to grant that the element
popped is always the greater in the priority queue.
----------------------
我想應該是小弟英文不太好 看不懂它到底在說啥= =
綠色那段好像事再說 cmp(a,b) function 裡面 return true 就代表 左邊的要
to be placed earlier then 右邊的
這給我的感覺像是如果我寫一個 Test class
然後在Test 裡面寫下
bool operator() (const Test& a , const Test& b){
if(a.value < b.value)
return true;
return false;
}
的話 priority 的順序應該是從小的value到大的value才對 = =
但是下面又說 operator(a<b) 會是從大到小排列
這樣讓我要記用法以後要寫的時候會有點confused 到底該return 啥 = =
是我英文不好還是怎樣呢??@@
謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.244.131
推
05/13 13:34, , 1F
05/13 13:34, 1F
→
05/13 13:35, , 2F
05/13 13:35, 2F
→
05/13 13:35, , 3F
05/13 13:35, 3F
→
05/13 13:36, , 4F
05/13 13:36, 4F
→
05/13 14:28, , 5F
05/13 14:28, 5F
→
05/13 14:29, , 6F
05/13 14:29, 6F
→
05/13 14:29, , 7F
05/13 14:29, 7F
→
05/13 21:22, , 8F
05/13 21:22, 8F
→
05/13 21:24, , 9F
05/13 21:24, 9F
→
05/13 21:24, , 10F
05/13 21:24, 10F
→
05/13 21:24, , 11F
05/13 21:24, 11F
推
05/13 21:31, , 12F
05/13 21:31, 12F
→
05/13 21:32, , 13F
05/13 21:32, 13F
→
05/13 21:47, , 14F
05/13 21:47, 14F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章