Let's define root like this (not valid C++, obviously):
root = {root[0], root[1], ..., root[root.size()-1]};
We can define another vector v:
v = {0, 1, ..., root.size()-1};
Note that for all natural i in [0;root.size()-1] v[i] == i.
Therefore, for all natural i in [0;root.size()-1] root[v[i]] == root[i].
In other words, v is a vector of indices of root.
A vector<T> x is considered sorted iff for all natural i in [0;v.size()-2] ¬f(x[i+1], x[i]), where f is some strict weak ordering of T.
What this code does is simply sort v by defining the strict weak ordering f(x,y) = root[x]<root[y]. Let's say that v' is the sorted version of v according to this ordering. We can now define a function g(i) = root[v'[i]]. g behaves as a sorted version of root: for all natural i in [0;v'.size()-2] ¬(g(i+1)<g(i)).
g is exemplified on line 26.
Now your job, as I stated on lines 7 and 8, is to define a strict weak ordering of node:
1 2 3
|
bool operator<(const node &the_other_node) const{
return /*...*/;
}
|