-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiset.cpp
More file actions
65 lines (52 loc) · 1.18 KB
/
multiset.cpp
File metadata and controls
65 lines (52 loc) · 1.18 KB
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
57
58
59
60
61
62
63
64
65
#include <iostream>
#include "multiset.hpp"
//////////////////////////////////////////////////////////////////////////////
void dump(auto n)
{
std::list<decltype(n)> q{n};
do
{
for (auto m(q.size()); m--;)
{
auto const n(q.front());
q.erase(q.begin());
if (n)
{
q.insert(q.end(), {n->l_, n->r_});
std::cout << '{' << n->key() << '}';
}
else
{
std::cout << "{null}";
}
std::cout << ' ';
}
std::cout << std::endl;
}
while (q.size() && std::any_of(q.cbegin(), q.cend(),
[](auto const p) noexcept { return p; }));
}
//////////////////////////////////////////////////////////////////////////////
int main()
{
sg::multiset<int> st;
st.emplace(-1);
st.insert(0);
st.insert({1, 1});
st.emplace(2);
st.emplace(3);
st.emplace(4);
dump(st.root());
std::cout << "count: " << st.count(1) << std::endl;
std::cout << "height: " << sg::detail::height(st.root()) << std::endl;
std::cout << "size: " << st.size() << std::endl;
std::for_each(
st.cbegin(),
st.cend(),
[](auto&& k) noexcept
{
std::cout << '(' << k << ')' << std::endl;
}
);
return 0;
}