-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LeetCode题解c++版本的P44页有问题 #27
Comments
Delete cur 后,cur 所指向的对象释放了,但cur只是个名字,这个名字还是可以复用的 On Tuesday, August 12, 2014, Lice Pan [email protected] wrote:
My tech blog: http://www.soulmachine.me |
delete cur之后cur->next还能引用?本人c++菜鸟,望指教:) |
这个问题我有看法,delete cur之后,cur当然那还能被附新值,但是继续使用cur->next 赋值且程序通过的原因是cur原来指向的内存没有被其他程序污染,所以可以找到cur->next,其实这样写是不太妥当的,我改成了下面这个写法,功能一样,就是防止面试官质疑: class Solution {
}; |
P44页讲到了Remove Duplicates from Sorted List的迭代解法,其中的一段代码片段:
既然
delete cur
语句已经将cur删除,为什么还可以在for的条件语句里执行cur = cur->next
?PS.感谢作者辛勤的劳动为我们带来了如此有价值的作品,再次感谢:)
The text was updated successfully, but these errors were encountered: