chap graphs static void topsort(graph /topological sortqueue queue new aqueue( ())int[count new int[ ()]int vfor ( = < () ++count[ /initialize for ( = < () ++/process every edge for (int first( ) () next(vw)count[ ]++/add to ' prereq count for ( = < () ++/initialize queue if (count[ = / has no prerequisites enqueue( )while ( length( /process the vertices dequeue(intvalue()printout( )/previsit for vertex for (int first( ) () next(vw)count[ ]--/one less prerequisite if (count[ = /this vertex is now free enqueue( )figure queue-based topological sort algorithm figure example graph for shortest-path definitions isthe weight of the direct connection from to because there is no edge from to bw(ebnote that (dabecause the graph of figure is directed we assume that all weights are positive single-source shortest paths this section presents an algorithm to solve the single-source shortest-paths problem given vertex in graph gfind shortest path from to every other vertex in we might want only the shortest path between two verticess and however in the worst casewhile finding the shortest path from to twe might find