DEV Community

loading...

Discussion on: A short summary of the Union-Find algorithm

Collapse
arj profile image
arj • Edited

For the last problem I'd suggest using a helper/factor as you mentioned:
auto t1 = make_tree(1);
auto t2 = make_tree(2);

which creates you a shared_ptr tree.

Implementation (untested code):

ˋˋˋ
template
std::shared_ptr> make_tree(const T& t) {
return std::make_shared>(t);
}
ˋˋˋ