Detect cycles in a genealogy graph during a Depth-first search
I'm loading horse genealogical data recursively. For some wrong sets of data my recursion never stops... and that is because there are cycles in the data. How can I detect those cycles to stop recurring? I thought of while recurring maintain a hashTable with all "visited" horses. But that will find some false positives, because a horse CAN be twice in a tree. What cannot happen is that a horse appear as a father or grandfather or great grandfather of ITSELF. Pseudo code: void ProcessTree(GenTreeNode currentNode, Stack<GenTreeNode> seen) { if(seen.Contains(currentNode)) return; // Or, do