Assume a std::set< std::pair<char, char> >
, can somebody suggest an algorithm or approach to check whether there are cyclic pairs?
e.g.
std::set< std::pair<char, char> > cyclic = { {'A', 'B'}, {'B', 'C'}, {'C', 'A'} };
std::set< std::pair<char, char> > not_cyclic = { {'A', 'B'}, {'B', 'C'}, {'C', 'C'} };
isCyclic(cyclic); // true
isCyclic(not_cyclic); // false
I don't want to use any extern library (c++ library is allowed), since the function bool isCyclic(const std::set< std::pair<char, char> >& set);
will only be used once and it should be overkill to #include
a big library like boost just for that one function...
Any ideas how to tackle this problem?