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

36 lines
607 B
Go
Raw Normal View History

package main
import (
"code.google.com/p/go-tour/tree"
"fmt"
)
2012-09-03 20:17:13 -07:00
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) {
2012-09-03 20:17:13 -07:00
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()
}