Visualize a tree: Difference between revisions

Visualize a tree en FreeBASIC
(→‎{{header|jq}}: enhance efficiency)
(Visualize a tree en FreeBASIC)
Line 1,676:
 
In '''[https://formulae.org/?example=Visualize_a_tree this]''' page you can see the program(s) related to this task and their results.
 
 
=={{header|FreeBASIC}}==
{{trans|Yabasic}}
<lang freebasic>Dim Shared As Ubyte colores(4) => {7,13,14,3,2}
 
Sub showTree(n As Integer, A As String)
Dim As Integer i, co = 0, b = 1, col
Dim As String cs = Left(A, 1)
If cs = "" Then Exit Sub
Select Case cs
Case "["
co += 1 : showTree(n + 1, Right(A, Len(A) - 1))
Exit Select
Case "]"
co -= 1 : showTree(n - 1, Right(A, Len(A) - 1))
Exit Select
Case Else
For i = 2 To n
Print " ";
co = n
Next i
Color colores(co) : Print !"\&hc0-"; cs
showTree(n, Right(A, Len(A) - 1))
Exit Select
End Select
End Sub
 
Cls
showTree(0, "[1[2[3][4[5][6]][7]][8[9]]]")
Print !"\n\n\n"
showTree(0, "[1[2[3[4]]][5[6][7[8][9]]]]")
Sleep</lang>
 
 
=={{header|Go}}==
2,156

edits