queue나 priority queue는 둘다 iterator가 없다.
priority queue는 max heap / min heap 사용 가능.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include "stdafx.h" #include <iostream> #include <map> #include <unordered_set> #include <string> #include <algorithm> #include <queue> #include <functional> using namespace std; int main() { priority_queue<pair<int, int>,vector<pair<int,int>>,greater<pair<int,int>>> tmp; tmp.push(pair<int, int>(1, 4)); tmp.push(pair<int, int>(1, 3)); tmp.push(pair<int, int>(1, 2)); tmp.push(pair<int, int>(1, 1)); tmp.push(pair<int, int>(2, 2)); tmp.push(pair<int, int>(3, 2)); tmp.push(pair<int, int>(4, 2)); tmp.push(pair<int, int>(5, 2)); while (tmp.size() != 0) { cout << tmp.top().first << " " << tmp.top().second << endl; tmp.pop(); } while(1){} queue<int> sam; for (int i = 0; i < 10; i++) { sam.push(i); } int t = sam.front(); t--; sam.front() -= 10; cout << sam.front() << endl; // 특이하게 int & 형태의 값을 리턴해서 이 값대로 바로 변경하면 값이 바뀐다. cout << sam.front() << endl; for (int i = 0; i < 5; i++) { sam.pop(); } while(1){} return 0; } | cs |