C++ disjoint set

C++ disjoint set

About disjoint set :

C++ Disjoint sets are very useful data structures that are used in many famous Algorithms, and you might consider using them in designing algorithms that include some sort of union behavior.
Here we show how to implement a Disjoint List efficiently using C++, and i consider that we already know what a Disjoint List is.
the source code is given below

Just an overview : the implementation for C++ disjoint set is as follows,
A list of disjoint nodes objects isa disjoint list, each node is holding a generic node of data_type defined by the user.
Each Disjoint Node has a list of all its childrens.

The node of our Disjoint list is called DisJointNode and it has the following structure,Core Node : a generic objectParent Pointer : pointer to the node’s parent in the disjoint listChildrens :a list of node’s children which we will use to iterate n the whole list

We must know :
when a Node is created, its initial parent is the node it self.

The DisjointList A Disjoint list will include pointer to a DisJointNode (root), all the nodes of a given list will be linked to the list’s root such that parent of a node is another node in the list or the root of the node,

Since we are using pass compression the method Find() sets x->parent = find(x->parent) until we reach the root node, this means that when find() is called again on the same node find() will return in O(1).

when the destructor ~DisjoinList() is called this means that the list is being deleted, at this point we must delete all the nodes of the list.