C# 中检测有向图中循环的简单实现
I wonder if you could help me with a simple implementation for detecting cycles in a directed graph in C#.
I've read about the algorithms but I'd like to find something already implemented, very simple and short.
I don't care about the performance because the data size is limited.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 QuickGraph - 它实现了很多算法,并且是一个非常好用的库。
Check out QuickGraph - it has loads of the algorithms implemented and it's quite a nice library to use.
在 G 上运行 DFS 并检查后端。
在您展开的每个节点上,只需检查它是否已经在当前路径中。
Run a DFS on G and check for backedges.
At every node you expand just check if it is already in the currrent path.