try

show tree 20
show qtree 20

-----a script for <tree display>--------------
NB. sorry for insufficent commnets

NB. --- (quasi) tree genertion
NB. input: # of nodes
NB. ouptut: predecessor

tree=:0: , [EMAIL PROTECTED]@i.

NB. input: # of nodes
NB. ouptut: predecessor of quasitree

qtree=:[EMAIL PROTECTED]


NB. show tree or quasi-tree
show=:0 1&$: : (showtree(;[EMAIL PROTECTED]))

NB.---showtree-----------------------------------

NB. opt : V;qtree(;nodemark) --> show qtree (DFS)
NB. opt==linespaceing,arcsize
NB.      0/1/0 1/1 0

showtree=: 4 : 0
'o0 o1'=.2{.,~x[nV=.#p=.W i. yy['W yy Whd'=.3{.y
SP=.>:o0[BX=.' ',(#:1947)#9!:6''
MK1=._3<\BX{~"."0'000048058828888868070018830'
MK=.".'MK',":o1[MK0=.<"0 BX{~"."0'045286713'
l=.<(7{BX),}.;{:ND=.<"1 ' ',~(":,.W) ,. ::[  Whd
R=. qroot p
X=.''[p=. nV,~nV (;R)}p
for_r. R do. K=./:~iq=.q#~i=.~:q=.p thread~ >r
 if. 1<#K do.
  mm=.#B=.(i#0,~2=/\q)<;.2 iq
  nn=.#D=.(i#+/\_1 1{~i) </. iq       NB. layer by depth
  IDX=.(#&> # [EMAIL PROTECTED])/:;
  bth=.IDX B[dth=.IDX D              NB. indexed by K
  ij=.SP*bth+dth*mm[s=.*/nm=.nn,mm*SP
  a=.(/:~>:@(+:@~: + ~:&.|.)@:{&p);D NB. indexed by DB
  'h t'=.(SP*mm)({.;}.)a ij}s#0
  t=.6(I.(t e. 1 3)~:(~:/\t e. 2 3))}t
  jl=.I.-.*h{.~jt=.1 i:~*h
  h=.(jt#6),2,}.jt}.h
  nd0=. MK{~h,t                      NB. arc line
  nd1=.l jl}(ND{~K) ij}s#{:ND        NB. node label
  nd=.,.>|:nm$nd0,&.>nd1
 else. nd=.,:(;2{MK),;K{ND end.
X=.X,<((;7{MK),3{BX),nd
end.
X
)


NB. qtree --> roots
qroot=: 3 : 0
c=./:[EMAIL PROTECTED]@({&y)^:_ y
(|.~ (i. <./))@|.@({&c)&.> C.(i.{&y) c
)


NB. t : qtree --> t-thread (DFS)
thread=: 4 : 0
q=.2#Q=.x[p=._ x}y
while. #Q do.i=.>:q i.k=.{.Q
  Q=.}.Q,K=.I.k=p
  q=.(i{.q),(2#K),i}.q
end. q
)
---- end of script ----------------------------------------
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to