fig list of leaders with zero count after all this preparatory establishing of convenient representation of the partially ordered set swe can finally proceed to the actual task of topological sortingi of generating the output sequence in first rough version it can be described as followsq :headwhile nil do (*output this elementthen delete it*texts writeint(wq key )dec( ) : trailq : nextdecrement the predecessor count of all its successors on trailer list tif any count becomes insert this element in the leader list end the statement that is to be still further refined constitutes one more scan of list in each stepthe auxiliary variable designates the leader element whose count has to be decremented and tested while nil do : iddec( count)if count then (*insert pin leader list* next :qq : endt : next end this completes the program for topological sorting note that counter was introduced to count the leaders generated in the input phase this count is decremented each time leader element is output in the output phase it should therefore return to zero at the end of the program its failure to return to zero is an indication that there are elements left in the structure when none is without predecessor in this case the set is evidently not partially ordered the output phase programmed above is an example of process that maintains list that pulsatesi in which elements are inserted and removed in an unpredictable order it is therefore an example of process which utilizes the full flexibility offered by the explicitly linked list var headtailleaderninteger(adens _topsort *procedure find (winteger)leadervar hleaderbegin :headtail key : (*sentinel*while key do : next endif tail then new(tail)inc( ) count : trail :nilh next :tail endreturn end findprocedure topsort (var rtexts reader)var pqleaderttrailer(*uses global writer *xyintegerbegin (*initialize list of leaders with dummy acting as sentinel*new(head)tail :headn :