sherxon / AlgoDS

Implementation of Algorithms and Data Structures, Problems and Solutions
http://sherxon.com
MIT License
3.43k stars 610 forks source link

CycleDetection #42

Closed aoyuanbo closed 6 years ago

aoyuanbo commented 6 years ago

Whether or not there is a cycle, this program always returns true after running ` for (Integer neighbor : graph.getNeighbors(start)) {

        if(visited.contains(neighbor) && !exited.contains(neighbor)) return true;

        if(!visited.contains(neighbor) && dfs(neighbor)) return true;
    }`
sherxon commented 6 years ago

Can you give any sample directed graph that returns true if there is no cycle?

aoyuanbo commented 6 years ago

I know what happened, I use the undirected graph.