BFS detecting cycles where it should not be
<p>I have implemented a BFS algorithm to detect cycles in a graph, this is the following code:</p>

<pre><code>            void hasCycle(node *root,string start){  
            if(root-&gt;visted){
                if(root-&gt;name == start) cout &lt;&lt; "Has cycle" &lt;&lt; endl;
                else return;
            }
            root-&gt;visted = true;
            int ind;
            for(ind = 0; ind &lt; root-&gt;adj.size(); ind++)
                hasCycle(root-&gt;adj[ind], start);
            root-&gt;visted = false;
            }
</code></pre>

<p>Where start is the starting node.
where node is the following struct:</p>

<pre><code>            struct node{
                string name;
                bool   visted;
                vector &lt;node *&gt; adj;
            };
</code></pre>

<p>This is the Graph that I have constructed:</p>

<pre><code>            Graph *grp = new Graph();
            grp-&gt;addVertex("A");
            grp-&gt;addVertex("B");
            grp-&gt;addVertex("C");

            grp-&gt;addEdge("A","B");
            grp-&gt;addEdge("B","A");
            grp-&gt;addEdge("A","C");
            grp-&gt;addEdge("C","A");
</code></pre>

<p>The output is:
                Has cycle
                Has cycle
                Has cycle</p>

<p>The correct output is nothing since there is no cycle. I have spent a lot of time trying to debug this, please help!</p>

<p>note: This is not a directed graph so I want them to be double edges</p>
