+ = and = 1+在爪哇
我和我的朋友一直在为学校解决问题。我们正在遍历带有DFS的图形,并计算每个给定组件中的节点数量。我们得到的结果很大,并且已经确定了差异的位置。
进入下一个递归时,我的朋友使用语法,
componentSize += DFS_visit(nextNodeToVisit);
而我
componentSize = 1 + DFS_visit(nextNodeToVisit);
最初使用的是这两个是相同的,那么有什么区别?在我们的情况下应该使用哪一个?
Me and my friend have been working on a problem for school. We are traversing a graph with DFS and are counting the number of nodes in each given component. We get widely different results and have identified where the difference lies.
When going into the next recursion, my friend uses the syntax
componentSize += DFS_visit(nextNodeToVisit);
whereas I use
componentSize = 1 + DFS_visit(nextNodeToVisit);
I originally thought these two were the same, so what is the difference? And which one should be used in our case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
意思是
将其与
差异进行比较吗?
通常,
a< op> = b
大致表示与a = a< op> b
其中< op>
操作员。 (a
的类型也有LHS的类型。)目前尚不清楚哪个是正确的。我们需要查看数据结构和更多算法。
means
Compare that with
See the difference?
In general
a <op>= b
means roughly the same asa = a <op> b
where<op>
an operator. (There is also a typecast of the LHS to the type ofa
.)It is not clear which is correct. We would need to see the data structure and more of the algorithm.