void graph::topsortqueue qint counter makeempty)for each vertex ifv indegree = enqueuev )while! isemptyvertex dequeue) topnum ++counter/assign next number for each vertex adjacent to if-- indegree = enqueuew )ifcounter !num_vertices throw cyclefoundexception}figure pseudocode to perform topological sort pseudocode implementation of this algorithm is given in figure as beforewe will assume that the graph is already read into an adjacency list and that the indegrees are computed and stored with the vertices we also assume each vertex has named data membertopnumin which to place its topological numbering the time to perform this algorithm is (| | |if adjacency lists are used this is apparent when one realizes that the body of the for loop is executed at most once per edge computing the indegrees can be done with the following codethis same logic shows that the cost of this computation is (| | |)even though there are nested loops for each vertex indegree for each vertex for each vertex adjacent to indegree++the queue operations are done at most once per vertexand the other initialization stepsincluding the computation of indegreesalso take time proportional to the size of the graph