RosettaCodeData/Task/Visualize-a-tree/Icon/visualize-a-tree.icon

15 lines
442 B
Plaintext

procedure main(A)
showTree("", " -", [1, [2,[3],[4,[5],[6]],[7,[11]]], [8,[9,[10]]] ])
write()
showTree("", " -", [1, [2,[3,[4]]], [5,[6],[7,[8],[9]],[10]] ])
end
procedure showTree(prefix, lastc, A)
write(prefix, lastc, "--", A[1])
if *A > 1 then {
prefix ||:= if prefix[-1] == "|" then " " else " "
every showTree(prefix||"|", "-", !A[2:2 < *A])
showTree(prefix, "`-", A[*A])
}
end