Sorting will tell you if an existing structure is invalid. If you are creating the structure, it's very easy to check by walking up the reports-to tree until you either get to the top (in which case it's OK), or to the reporter (in which case it's a cycle).

(it might also be worth pointing out that in large organisations it's generally roles rather than people which report to each other, so you can get two people who report to each other in different aspects of their jobs)