Skip to content

Commit 66340cd

Browse files
First Commit (priority_queue, set and multiset)
1 parent 0fe4300 commit 66340cd

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

STL2.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
priority_queue<T> pq;
2+
Features:
3+
- Max heap tree.
4+
- Keeps the maximum value on top of the Tree.
5+
6+
Commonly used Member functions:
7+
- size()
8+
- empty()
9+
- push(val) //O(log(n))
10+
- pop() //Avoid RTE
11+
- top() //Avoid RTE
12+
13+
Iteration:
14+
while(!pq.empty()){
15+
printf("%d ", pq.top());
16+
pq.pop();
17+
}
18+
19+
-What if we want to get the minimum values?
20+
1- Multiply values by -1.
21+
2- Use greater Comparator.
22+
23+
24+
set<T> st;
25+
26+
Features:
27+
- Red Black tree -Balanced Binary Search tree-.
28+
- No Duplicates.
29+
- Seems to be sorted Ascendingly.
30+
- search, insert and erase in O(log(n))
31+
32+
Commonly used Member functions:
33+
- begin()
34+
- end()
35+
- rbegin()
36+
- rend()
37+
- insert(val)
38+
- find(val) //iterator
39+
- count(val) // 0|1
40+
- erase(val) || erase(iterator)
41+
- lower_bound(val) //iterator where >= val
42+
- upper_bound(val) //iterator where > val
43+
- size()
44+
- empty()
45+
- clear()
46+
47+
Iteration:
48+
for(auto x : st){
49+
printf("%d", x);
50+
}
51+
52+
for(auto it = st.begin() ; it != st.end() ; ++it){
53+
printf("%d", *it);
54+
}
55+
56+
multiset<T> ms; //the same as set but allows Duplicates.

0 commit comments

Comments
 (0)