2019/c++

STL Queues

fw93 2018. 3. 28. 13:16

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<intint>,vector<pair<int,int>>,greater<pair<int,int>>> tmp;
    tmp.push(pair<intint>(14));
    tmp.push(pair<intint>(13));
    tmp.push(pair<intint>(12));
    tmp.push(pair<intint>(11));
    tmp.push(pair<intint>(22));
    tmp.push(pair<intint>(32));
    tmp.push(pair<intint>(42));
    tmp.push(pair<intint>(52));
    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


'2019 > c++' 카테고리의 다른 글

IO  (0) 2018.03.30
File I/O  (0) 2018.03.30
SORTING  (0) 2018.03.26
maps STL  (0) 2018.03.25
variables and memory, declaration  (0) 2018.03.24