# outputs nested html tables to visualise a tree # # mode representing nodes of the tree # MODE NODE = STRUCT( STRING value, REF NODE child, REF NODE sibling ); REF NODE nil node = NIL; # tags etc. # STRING table = "" , elbat = "
" , tr = "" , rt = "" , td = "" + nbsp + value OF tree + nbsp + dt + nl + rt + nl ; IF child count > 0 THEN # the node has branches # REF NODE child := child OF tree; INT child number := 1; INT mid child = ( child count + 1 ) OVER 2; child := child OF tree; result +:= tr + nl; WHILE child ISNT nil node DO result +:= td + ">" + nl + IF CHILDCOUNT child < 1 THEN nbsp + value OF child + nbsp ELSE TOHTML child FI + dt + nl; child := sibling OF child OD; result +:= rt + nl FI; result +:= elbat + nl FI # TOHTML # ; # test the tree visualisation # # returns a new node with the specified value and no child or siblings # PROC new node = ( STRING value )REF NODE: HEAP NODE := NODE( value, nil node, nil node ); # appends a sibling node to the node n, returns the sibling # OP +:= = ( REF NODE n, REF NODE sibling node )REF NODE: BEGIN REF NODE sibling := n; WHILE REF NODE( sibling OF sibling ) ISNT nil node DO sibling := sibling OF sibling OD; sibling OF sibling := sibling node END # +:= # ; # appends a new sibling node to the node n, returns the sibling # OP +:= = ( REF NODE n, STRING sibling value )REF NODE: n +:= new node( sibling value ); # adds a child node to the node n, returns the child # OP /:= = ( REF NODE n, REF NODE child node )REF NODE: child OF n := child node; # adda a new child node to the node n, returns the child # OP /:= = ( REF NODE n, STRING child value )REF NODE: n /:= new node( child value ); NODE animals := new node( "animals" ); NODE fish := new node( "fish" ); NODE reptiles := new node( "reptiles" ); NODE mammals := new node( "mammals" ); NODE primates := new node( "primates" ); NODE sharks := new node( "sharks" ); sharks /:= "great-white" +:= "hammer-head"; fish /:= "cod" +:= sharks +:= "piranha"; reptiles /:= "iguana" +:= "brontosaurus"; primates /:= "gorilla" +:= "lemur"; mammals /:= "sloth" +:= "horse" +:= "bison" +:= primates; animals /:= fish +:= reptiles +:= mammals; print( ( TOHTML animals ) )