breadth first search in c using algorithm given by cormen -


/ P>

  bfs (int s) {int i; Int u, v; Straight edge * e; Graph [s] .colour = 1; Graph [s] .D = 0; Graph [s] .pre = -1; Queued (s); While (isempty ()! = 1) {u = dequeue (); Printf ("% d \ t", U); E = graph [u] .edgePtr; While (e = = null) {v = e-> vertexIndex; If (article [V] .colour == WHITE) {graph [v] .colour = Gray; Graph [V]. = Graph [u]. + 1; Graph [V] .Pre = U; Queue (v); E = E & gt; EdgePtr; } Graph [u] .colour = black; }}}   

im getting an infinite loop ... can someone tell me how is it going wrong ??

you've added your closing } . As a result, if you have the WHITE color, you only go to the next edge, and if the color of u in the infinite code is non- white < / Code>. The correct form should look like this:

  bfs (int s) {// รข ?? | While (isempty ()! = 1) {u = dequeue ()); // One ?? | While (e! = Null) {v = e-> gt; VertexIndex; If (article [V] .colour == WHITE) {graph [v] .colour = Gray; Graph [V]. = Graph [u]. + 1; Graph [V] .Pre = U; Queue (v); } // end if white e = e-> Shore; // Update e for all colors! } // End loop on all edges and graphs [u] Color = black; } // and loop while the queue is not empty // // function    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -