Skip to content

Instantly share code, notes, and snippets.

@vly
Created April 21, 2013 09:49
Show Gist options
  • Save vly/5429111 to your computer and use it in GitHub Desktop.
Save vly/5429111 to your computer and use it in GitHub Desktop.
Golang tour #69
package main
import ("code.google.com/p/go-tour/tree"
"fmt"
)
func Walk(t *tree.Tree, ch chan int) {
Walker(t, ch)
close(ch)
}
func Walker(t *tree.Tree, ch chan int) {
if t == nil {return}
Walker(t.Left, ch)
ch <- t.Value
Walker(t.Right, ch)
}
func Same(t1, t2 *tree.Tree) bool {
ch:=make(chan int)
go Walk(t1, ch)
ch2:= make(chan int)
go Walk(t2, ch2)
for n := range ch {
if n == <- ch2 {return true}
}
return false
}
func main() {
fmt.Print(Same(tree.New(1), tree.New(2)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment