Note that std::list sorts the element according to the operator< defined for that element. You need to change the compare function to use the global operator< defined for Node objects:
bool operator<(Node const& first, Node const& second) { unsigned int ii =0; while (ii < length) { if (first.Value[ii] < second.Value[ii]) { return true; } else if (first.Value[ii] > second.Value[ii]) { return false; } ++ii; } return false;
}
The proposed improvement will be:
bool operator<(Node const& first, Node const& second) { for (size_t ii =0; first.Value[ii] == second.Value[ii]; ++ii) ;
If char *Value really represents a C-style string, and you want lexicographic sorting, further improvements are possible:
bool operator<(Node const& first, Node const& second) { return (strcmp(first.Value, second.Value) < 0); }
and if they are really strings, I suggest you use std::string , and you can write:
bool operator<(Node const& first, Node const& second) { return first.Value < second.Value; }
source share