作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Initstmt在循环中
目标是在下面的代码中添加两棵树并返回一棵新树:
/*
3 3
/ \ / \
/ \ / \
1 2 1 2
/ \ /
/ \ /
1 1 1
*/
/*
1) Tree has root label and list of branches
2) Each branch is again a tree
*/
type Tree struct {
rootLabel int
branches []Tree
}
func addTrees(t1 Tree, t2 Tree) Tree {
if isLeaf(t1) {
return Tree{}
}
firstTreeBranches := branches(t1)
secondTreeBranches := branches(t2)
for branch1:= firstTreeBranches[0], branch2:= secondTreeBranches[0];;{
}
}
func branches(t Tree) []Tree {
return t.branches
}
addTrees(branch1,branch2)
在上面的代码中。
最佳答案
您可以使用以下方法实现此目的:
for branch1, branch2 := firstTreeBranches[0], secondTreeBranches[0] ; ; {
...
}
Try it on the playground .引用
Variable declaration了解更多信息。
关于go - 如何在for循环中使用两个initStmt?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63542065/
我是一名优秀的程序员,十分优秀!