forked from Muhammad-Magdi/problem-solving
-
Notifications
You must be signed in to change notification settings - Fork 0
/
STL2.txt
56 lines (46 loc) · 1.14 KB
/
STL2.txt
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
44
45
46
47
48
49
50
51
52
53
54
55
56
priority_queue<T> pq;
Features:
- Max heap tree.
- Keeps the maximum value on top of the Tree.
Commonly used Member functions:
- size()
- empty()
- push(val) //O(log(n))
- pop() //Avoid RTE
- top() //Avoid RTE
Iteration:
while(!pq.empty()){
printf("%d ", pq.top());
pq.pop();
}
-What if we want to get the minimum values?
1- Multiply values by -1.
2- Use greater Comparator.
set<T> st;
Features:
- Red Black tree -Balanced Binary Search tree-.
- No Duplicates.
- Seems to be sorted Ascendingly.
- search, insert and erase in O(log(n))
Commonly used Member functions:
- begin()
- end()
- rbegin()
- rend()
- insert(val)
- find(val) //iterator
- count(val) // 0|1
- erase(val) || erase(iterator)
- lower_bound(val) //iterator where >= val
- upper_bound(val) //iterator where > val
- size()
- empty()
- clear()
Iteration:
for(auto x : st){
printf("%d", x);
}
for(auto it = st.begin() ; it != st.end() ; ++it){
printf("%d", *it);
}
multiset<T> ms; //the same as set but allows Duplicates.