描述
C++複製構造函數std::priority_queue::priority_queue()使用現有 priority_queue 中存在的每個元素的副本構造一個 priority_queue其他。
聲明
以下是 std::priority_queue::priority_queue() 構造函數形式 std::queue 頭的聲明。
C++11
priority_queue( const priority_queue& other );
參數
other- 另一個相同類型的 priority_queue 對象。
返回值
構造函數從不返回值。
異常
此成員函數從不拋出異常。
時間複雜度
線性,即 O(n)
示例
下麵的例子展示了 std::priority_queue::priority_queue() 構造函數的用法。
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main(void) {
vector<int> v = {3, 1, 5, 2, 4};
priority_queue<int> q1(less<int>(), v);
priority_queue<int> q2(q1);
cout << "Contents of q1" << endl;
while (!q1.empty()) {
cout << q1.top() << endl;
q1.pop();
}
cout << endl;
cout << "Contents of q2" << endl;
while (!q2.empty()) {
cout << q2.top() << endl;
q2.pop();
}
return 0;
}
讓我們編譯並運行上麵的程序,這將產生以下結果——
Contents of q1 5 4 3 2 1 Contents of q2 5 4 3 2 1
相關用法
- C++ Queue swap()用法及代碼示例
- C++ Queue emplace()用法及代碼示例
- C++ Queue push()用法及代碼示例
- C++ Queue top()用法及代碼示例
- C++ Queue front()用法及代碼示例
- C++ Queue priority_queue()用法及代碼示例
- C++ Queue back()用法及代碼示例
- C++ Queue size()用法及代碼示例
- C++ Queue empty()用法及代碼示例
- C++ Queue pop()用法及代碼示例
- C++ unordered_map cbegin用法及代碼示例
- C++ map lower_bound()用法及代碼示例
- C++ Unordered_multimap reserve()用法及代碼示例
- C++ list assign()用法及代碼示例
- C++ std::max()用法及代碼示例
- C++ std::string::push_back()用法及代碼示例
- C++ Array swap()用法及代碼示例
- C++ multimap key_comp()用法及代碼示例
- C++ Deque erase()用法及代碼示例
- C++ List cend()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ Queue Library - queue() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。