Skip to content

Waiyva/binary-tree-visible

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BTPrinter

Print binary tree in extremely small area for go language

BTPrinter

About

To practise algorithm quicker, code Visual binary tree for ready

Installation

  1. use tool go get

go get -u github.com/waiyva/binary-tree

  1. download code to your $GOPATH

Example

  1. 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
    
    
  2. 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  
    
    

Others

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!

About

Print binary tree in extremely small area, go implement

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages