Visualize a tree: Difference between revisions

Content added Content deleted
(Go solution)
(Added BBC BASIC)
Line 3:
 
'''Task''': Write a program to produce a visual representation of some tree. The content of the tree doesn't matter, nor does the output format, the only requirement being that the output is human friendly. Make do with the vague term "friendly" the best you can.
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
This creates a native Windows Tree View control:
<lang bbcbasic> INSTALL @lib$+"WINLIB5"
ON ERROR SYS "MessageBox", @hwnd%, REPORT$, 0, 0 : QUIT
REM!WC Windows constants:
TVI_SORT = -65533
TVIF_TEXT = 1
TVM_INSERTITEM = 4352
TVS_HASBUTTONS = 1
TVS_HASLINES = 2
TVS_LINESATROOT = 4
REM. TV_INSERTSTRUCT
DIM tvi{hParent%, \
\ hInsertAfter%, \
\ mask%, \
\ hItem%, \
\ state%, \
\ stateMask%, \
\ pszText%, \
\ cchTextMax%, \
\ iImage%, \
\ iSelectedImage%,\
\ cChildren%, \
\ lParam% \
\ }
SYS "InitCommonControls"
hTree% = FN_createwindow("SysTreeView32", "", 0, 0, @vdu.tr%, @vdu.tb%, 0, \
\ TVS_HASLINES OR TVS_HASBUTTONS OR TVS_LINESATROOT, 0)
hroot% = FNinsertnode(0, "Root")
hchild1% = FNinsertnode(hroot%, "Child 1")
hchild2% = FNinsertnode(hroot%, "Child 2")
hchild11% = FNinsertnode(hchild1%, "Grandchild 1")
hchild12% = FNinsertnode(hchild1%, "Grandchild 2")
hchild21% = FNinsertnode(hchild2%, "Grandchild 3")
hchild22% = FNinsertnode(hchild2%, "Grandchild 4")
REPEAT
WAIT 1
UNTIL FALSE
END
DEF FNinsertnode(hparent%, text$)
LOCAL hnode%
text$ += CHR$0
tvi.hParent% = hparent%
tvi.hInsertAfter% = TVI_SORT
tvi.mask% = TVIF_TEXT
tvi.pszText% = !^text$
SYS "SendMessage", hTree%, TVM_INSERTITEM, 0, tvi{} TO hnode%
IF hnode% = 0 ERROR 100, "TVM_INSERTITEM failed"
SYS "InvalidateRect", hTree%, 0, 0
= hnode%</lang>
[[File:visualize_tree_bbc.gif]]
 
=={{header|C}}==