(*input phase*texts scan( )while class texts int do : itexts scan( ) : ip :find( ) :find( )new( ) id :qt next : trailp trail :tinc( count)texts scan(send(*search for leaders without predecessors* :headhead :nilwhile tail do :pp : nextif count then (*insert in new chain* next :headhead : end end(*output phase* :headwhile nil do texts writeln( )texts writeint(wq key )dec( ) : trailq : nextwhile nil do : iddec( count)if count then (*insert in leader list* next :qq : endt : next end endif then texts writestring( "this set is not partially ordered"endtexts writeln(wend topsort tree structures basic concepts and definitions we have seen that sequences and lists may conveniently be defined in the following waya sequence (listwith base type is either the empty sequence (list the concatenation (chainof and sequence with base type hereby recursion is used as an aid in defining structuring principlenamelysequencing or iteration sequences and iterations are so common that they are usually considered as fundamental patterns of structure and behaviour but it should be kept in mind that they can be defined in terms of recursionwhereas the reverse is not truefor recursion may be effectively and elegantly used to define much more sophisticated structures trees are well-known example let tree structure be defined as followsa tree structure with base type is either the empty structure