(*input phase*new(head)tail :headtexts scan( )while class texts int do : itexts scan( ) : ip :find( ) :find( )new( ) id :qt next : trailp trail :tinc( count)texts scan(send tail head key count next trail id next id next fig list structure generated by topsort program after the data structure of fig has been constructed in this input phasethe actual process of topological sorting can be taken up as described above but since it consists of repeatedly selecting an element with zero count of predecessorsit seems sensible to first gather all such elements in linked chain since we note that the original chain of leaders will afterwards no longer be neededthe same field called next may be used again to link the zero predecessor leaders this operation of replacing one chain by another chain occurs frequently in list processing it is expressed in detail hereand for reasons of convenience it constructs the new chain in reverse order (*search for leaders without predecessors* :headhead :nilwhile tail do :pp : nextif count then (*insert qin new chain* next :headhead : end end referring to fig we see that the next chain of leaders is replaced by the one of fig in which the pointers not depicted are left unchanged nil head