本文整理汇总了Golang中golang.org/x/tour/tree.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
}
开发者ID:ng-vu,项目名称:Exercise,代码行数:7,代码来源:equivalenttree.go
示例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)
}
开发者ID:matijavizintin,项目名称:tour-of-go,代码行数:7,代码来源:trees_test.go
示例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)))
}
开发者ID:Skarlso,项目名称:gotour,代码行数:7,代码来源:go_binarytree.go
示例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(".")
}
}
}
开发者ID:alexzabolotny,项目名称:go-bootcamp,代码行数:28,代码来源:tree_test.go
示例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")
}
}
开发者ID:fernandoalmeida,项目名称:studies,代码行数:7,代码来源:exercise-equivalent-binary-trees.go
示例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)))
}
}
开发者ID:filipegoncalves,项目名称:go-samples,代码行数:8,代码来源:btrees.go
示例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)))
}
开发者ID:frankobe,项目名称:goTourExerciseSolution,代码行数:9,代码来源:exercise-equivalent-binary-trees.go
示例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)))
}
开发者ID:dontuta,项目名称:GoLanguage,代码行数:9,代码来源:equivalent_binary_trees.go
示例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))
}
开发者ID:NewRegin,项目名称:Golang,代码行数:9,代码来源:12_EquivalentBT.go
示例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)))
}
开发者ID:bisco,项目名称:shakyo,代码行数:9,代码来源:exercise-equivalent-binary-trees.go
示例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)))
}
开发者ID:FulcronZ,项目名称:GoTour,代码行数:10,代码来源:73-exercise-equivalent-binary-trees.go
示例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)))
}
开发者ID:Tao-Ma,项目名称:practise,代码行数:11,代码来源:exercise-equivalent-binary-trees.go
示例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")
}
开发者ID:nteissler,项目名称:tourofgo,代码行数:11,代码来源:exercise-equivalent-binary-trees.go
示例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)))
}
开发者ID:tangfeixiong,项目名称:go-to-exercise,代码行数:12,代码来源:exercise-equivalent-binary-trees.go
示例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)))
}
开发者ID:Harpreet4u,项目名称:goTour,代码行数:12,代码来源:equivalent-binary-trees.go
示例16: main
func main() {
// 2. テストとは、といった感じだけど
ch := make(chan int)
go Walk(tree.New(1), ch)
for v := range ch {
fmt.Println(v)
}
// 4.
fmt.Println(Same(tree.New(1), tree.New(1)))
fmt.Println(Same(tree.New(1), tree.New(2)))
}
开发者ID:gomachan46,项目名称:tour_of_go_challenge,代码行数:12,代码来源:concurrency.go
示例17: main
//Learning material used from
//https://tour.golang.org/concurrency/7
//https://tour.golang.org/concurrency/8
//This won't work if not run on the golang site.
func main() {
ch := make(chan int)
go Walk(tree.New(1), ch)
for i := 0; i < 10; i++ {
v := <-ch
fmt.Println(v)
}
fmt.Println(Same(tree.New(1), tree.New(1)))
fmt.Println(Same(tree.New(1), tree.New(2)))
}
开发者ID:Valkrysa,项目名称:FirstGo,代码行数:17,代码来源:BinaryTrees.go
示例18: main
func main() {
ch1 := make(chan int)
ch2 := make(chan int)
go Walk(tree.New(1), ch1)
go Walk(tree.New(2), ch2)
for i := 0; i < 10; i++ {
fmt.Println(<-ch1)
}
for i := 0; i < 10; i++ {
fmt.Println(<-ch2)
}
fmt.Println(Same(tree.New(1), tree.New(2)))
}
开发者ID:purepennons,项目名称:startLearnGolang,代码行数:14,代码来源:main.go
示例19: Same
// Same determines whether the trees
// t1 and t2 contain the same values.
func Same(t1, t2 *tree.Tree) bool {
ch1 := make(chan int)
ch2 := make(chan int)
go Walk(tree.New(10), ch1)
go Walk(tree.New(10), ch2)
for i := 0; i < 10; i++ {
a, b := <-ch1, <-ch2
if a != b {
return false
}
}
return true
}
开发者ID:rendon,项目名称:gosnippets,代码行数:16,代码来源:8.go
示例20: main
func main() {
var t *tree.Tree
t = tree.New(2)
if t.Left.Left.Left == nil {
fmt.Println("haha")
} else {
fmt.Println("hoho")
}
if Same(tree.New(1), tree.New(1)) {
fmt.Println("test1 passed")
}
if !Same(tree.New(1), tree.New(2)) {
fmt.Println("test2 passed")
}
}
开发者ID:yuquanshan,项目名称:myATourOfGoSol,代码行数:15,代码来源:equivalentBinaryTrees.go
注:本文中的golang.org/x/tour/tree.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论