graph - While loop, cout only the shortest path C++ -


Shows me the output shortcut of the graph from one peak to another. The production of that inspiration is in all ways, how to move from one over to another. Maybe I'm tired, but I can not solve it, thanks for help zero search path (string source, string trgt) {vector & gt; Path; Top * source = name_to_vertex [src]; Top * target = name_to_vertex [trgt];

  path.push_back (pair & lieutenant; header *, interp (source, 0)); From queue & lt; The vector & lt; Pair & lt; Top *, integer & gt; & Gt; & Gt; Q; q.push (path); Int i = 1; While (! Q.empty ()) {path = q.front (); q.pop (); Top * last_odef_path = path [path.size () - 1]. Fast; If (last_nodeof_path == target) {if (path.back (). Second & lt; 1) // second door pozisia etteraa {cout & lt; & Lt; "Path:"; print_path (path); Cout & lt; & Lt; "\ N"; }} Set & lieutenant; Edge * & gt; :: Iterator; (This is = last_odox_path-> edges.bgi); this! = Final_odox_path-> Edges.and (); ++) {if (isadjacency_node_not_present_in_current_path ((this *) -> getOposite (last_nodeof_path), path)) {vector & lieutenant; Pair and lieutenant; Header *, Intimate & gt; & Gt; new_path (path.begin (), path.end ()); Pinnacle * sused = (* it) - & gt; getOposite (last_nodeof_path); Pair and lieutenant; Header *, Int & gt; Equal (sused, (* this) -> gt = dist + new_path [new_path.size () - 1] .second); new_path.push_back (equals); q.push (new_path); }}} Cout & lt; & Lt; "No Path"; }    

Try adding a brake; If your if (last_nodeof_path == target) block, thus you print the answer first and end the execution of the main loop.

Comments

Popular posts from this blog

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -

jasper reports - How to center align barcode using jasperreports and barcode4j -

django - CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False -