Print binary tree in extremely small area for go language
To practise algorithm quicker, code Visual binary tree for ready
- use tool go get
go get -u github.com/waiyva/binary-tree
- download code to your $GOPATH
-
You can use string with ' , '
import "github.com/waiyva/binary-tree/btprinter" func main() { btprinter.PrintTree("1,2,3") }
1 / \ 2 3
import "github.com/waiyva/binary-tree/btprinter" func main() { btprinter.PrintTree("1,2,3,4,5,#,#,6,7,8,1,#,#,#,#,#,#,2,3,4,5,6,7,8,9,10,11,12,13,14,15") }
1 / \ 2 3 / \ / \ 4 5 / \ / \ 6 7 8 1 / \ / \ / \ / \ / \ 2 3 / \ / \ / \ / \ 4 5 6 7 / \ / \ / \ / \ 8 9 10 11 12 13 14 15
-
You can also use slice like the following
import "github.com/waiyva/binary-tree/btprinter" func main() { btprinter.PrintTree([]string{"animal", "dog", "cat", "Beagle", "Tottweiler", "Persian", "#"}) }
animal / \ / \ / \ / \ dog cat / \ / / \ Persian / \ / \ Beagle Tottweiler
I 'm go beginner, so there may be some nonstandard code here. Welcome to make issue.
Ideas come from Java version https://github.com/afkbrb/binary-tree-printer
Thanks!