You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
491 B

package huffman
import (
"fmt"
"io"
)
func printNode(w io.Writer, n *Node) {
if n.typ == MID {
fmt.Fprintf(w, "\"%v\" -> {\"%v\" \"%v\"}\n", n.String(), n.l.String(), n.r.String())
printNode(w, n.l)
printNode(w, n.r)
} else if n.typ == LEAF {
fmt.Fprintf(w, "\"%v\" [style=filled];\n", n.String())
}
}
func printTree(w io.Writer, n *Node) {
fmt.Fprintf(w, `digraph hierarchy {
node [fontname=Monospace,fontsize=10,shape=box]
`)
printNode(w, n)
fmt.Fprintf(w, "}\n")
}