Tree from nesting levels: Difference between revisions
Content added Content deleted
(Added XPL0 example.) |
(Tree from nesting levels in FreeBASIC) |
||
Line 704: | Line 704: | ||
In '''[https://formulae.org/?example=Tree_from_nesting_levels this]''' page you can see the program(s) related to this task and their results. |
In '''[https://formulae.org/?example=Tree_from_nesting_levels this]''' page you can see the program(s) related to this task and their results. |
||
=={{header|FreeBASIC}}== |
|||
<syntaxhighlight lang="vb">Sub ShowTree(List() As Integer) |
|||
Dim As Integer I, NestLevel = 0 |
|||
For I = 0 To Ubound(List) |
|||
While List(I) < NestLevel |
|||
Print "]"; |
|||
NestLevel -= 1 |
|||
Wend |
|||
If List(I) = 0 Then |
|||
Print |
|||
Elseif I <> Lbound(List) Then Print ", "; |
|||
End If |
|||
While List(I) > NestLevel |
|||
Print "["; |
|||
NestLevel += 1 |
|||
Wend |
|||
If NestLevel <> 0 Then Print NestLevel; |
|||
Next I |
|||
End Sub |
|||
Dim As Integer list(0 To ...) = {0} |
|||
ShowTree(list()) |
|||
Dim As Integer list0(0 To ...) = {1, 2, 4, 0} |
|||
ShowTree(list0()) |
|||
Dim As Integer list1(0 To ...) = {3, 1, 3, 1, 0} |
|||
ShowTree(list1()) |
|||
Dim As Integer list2(0 To ...) = {1, 2, 3, 1, 0} |
|||
ShowTree(list2()) |
|||
Dim As Integer list3(0 To ...) = {3, 2, 1, 3, 0} |
|||
ShowTree(list3()) |
|||
Dim As Integer list4(0 To ...) = {3, 3, 3, 1, 1, 3, 3, 3, 0} |
|||
ShowTree(list4()) |
|||
Dim As Integer list5(0 To ...) = {1, 2, 4, 2, 2, 1, 0} |
|||
ShowTree(list5()) |
|||
Sleep</syntaxhighlight> |
|||
{{out}} |
|||
<pre> 'Note that [0] displays nothing. |
|||
[ 1, [ 2, [[ 4]]]] |
|||
[[[ 3]], 1, [[ 3]], 1] |
|||
[ 1, [ 2, [ 3]], 1] |
|||
[[[ 3], 2], 1, [[ 3]]] |
|||
[[[ 3, 3, 3]], 1, 1, [[ 3, 3, 3]]] |
|||
[ 1, [ 2, [[ 4]], 2, 2], 1]</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |