本文整理汇总了Golang中golang.org/x/tour/tree.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
t1 := tree.New(1)
t2 := tree.New(1)
fmt.Println("t1:", t1)
fmt.Println("t2:", t2)
fmt.Println(Same(t1, t2))
}
示例2: TestSame
func TestSame(t *testing.T) {
result := Same(tree.New(1), tree.New(1))
fmt.Println(result)
result = Same(tree.New(1), tree.New(2))
fmt.Println(result)
}
示例3: main
func main() {
ch := make(chan int)
go Walk(tree.New(1), ch)
fmt.Println(Same(tree.New(1), tree.New(1)))
fmt.Println(Same(tree.New(1), tree.New(2)))
}
示例4: TestWalk
func TestWalk(t *testing.T) {
cases := []struct {
in *tree.Tree
want [10]int
}{
{tree.New(1), [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}},
{tree.New(2), [10]int{2, 4, 6, 8, 10, 12, 14, 16, 18, 20}},
}
for _, c := range cases {
ch := make(chan int)
go Walk(c.in, ch)
var walked [10]int
i := 0
for v := range ch {
walked[i] = v
i++
}
if walked != c.want {
t.Errorf("got: %v", walked)
} else {
fmt.Print(".")
}
}
}
示例5: main
func main() {
if Same(tree.New(1), tree.New(1)) && !Same(tree.New(1), tree.New(2)) {
fmt.Println("PASSED")
} else {
fmt.Println("FAILED")
}
}
示例6: main
func main() {
for i := 0; i < 10; i++ {
fmt.Println("Same(tree.New(1), tree.New(1)) =", Same(tree.New(1), tree.New(1)))
}
for i := 0; i < 10; i++ {
fmt.Println("Same(tree.New(1), tree.New(2)) =", Same(tree.New(1), tree.New(2)))
}
}
示例7: main
func main() {
// ch := make(chan int)
// go Walk(tree.New(2), ch)
// for v := range ch {
// fmt.Print(v)
// }
fmt.Println(Same(tree.New(1), tree.New(1)))
fmt.Println(Same(tree.New(1), tree.New(2)))
}
示例8: main
func main() {
ch := make(chan int, 10)
go Walk(tree.New(1), ch)
for i := 0; i < cap(ch); i++ {
fmt.Println(<-ch)
}
fmt.Println(Same(tree.New(1), tree.New(1)))
fmt.Println(Same(tree.New(1), tree.New(2)))
}
示例9: main
func main() {
t1 := tree.New(1)
t2 := tree.New(2)
t3 := tree.New(1)
//New()生成的树为二叉搜索树,这个方法只能解决二叉搜索树的等价分析问题。
fmt.Println(Same(t1, t3))
fmt.Println(Same(t1, t2))
}
示例10: main
func main() {
ch := make(chan int)
go Walk(tree.New(1), ch)
for i := range ch {
fmt.Println(i)
}
fmt.Println(Same(tree.New(1), tree.New(1)))
fmt.Println(Same(tree.New(1), tree.New(2)))
}
示例11: main
func main() {
ch := make(chan int)
go Walk(tree.New(1), ch)
for i := 1; i <= 10; i++ {
fmt.Println(<-ch)
}
fmt.Println(Same(tree.New(1), tree.New(1)))
fmt.Println(Same(tree.New(1), tree.New(2)))
}
示例12: main
func main() {
ch := make(chan int)
t := tree.New(1)
go func() { Walk(t, ch); close(ch) }()
for i := range ch {
fmt.Println(i)
}
fmt.Println(Same(tree.New(1), tree.New(1)))
fmt.Println(Same(tree.New(1), tree.New(2)))
}
示例13: main
func main() {
/*ch := make(chan int)
go Walk(tree.New(1), ch)
for i := 0; i < 10; i++ {
fmt.Println(<-ch)
}*/
fmt.Println("going")
fmt.Println(Same(tree.New(1), tree.New(1)))
fmt.Println(Same(tree.New(1), tree.New(2)))
fmt.Println("gone")
}
示例14: main
func main() {
ch := make(chan int)
go Walk(tree.New(1), ch)
for ok := true; ok; {
var v int
v, ok = <-ch
if ok {
fmt.Print(v, ", ")
}
}
fmt.Println(Same(tree.New(2), tree.New(2)))
}
示例15: main
func main() {
//tree.New(2)
ch := make(chan int)
ch1 := make(chan int)
go Walk(tree.New(1), ch)
for v := range ch {
fmt.Print(v)
}
fmt.Println(Same(tree.New(1), tree.New(1)))
fmt.Println(Same(tree.New(1), tree.New(2)))
}