1
0
Fork 0
gotour-notes/exercises/08-ebt/go.go

36 lines
607 B
Go

package main
import (
"code.google.com/p/go-tour/tree"
"fmt"
)
func walk(t *tree.Tree, ch chan int) {
if t != nil {
walk(t.Left, ch)
ch <- t.Value
walk(t.Right, ch)
}
}
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {
walk(t, ch)
close(ch)
}
// Same determines whether the trees
// t1 and t2 contain the same values.
func Same(t1, t2 *tree.Tree) bool
func main() {
t := tree.New(1)
ch := make(chan int)
go Walk(t, ch)
fmt.Printf("%v\n", t)
for i := range ch {
fmt.Printf("%d, ", i)
}
fmt.Println()
}