Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
``修改 main.cpp,改良其中的双链表类
List
:修改print函数参数为常量引用。
使用shared_ptr会导致循环引用,因此在List释放head以后,Node无法被释放
修改next和prev为
减少了shared_ptr的增加的atomic变量。解决了循环引用问题
改用
unique_ptr<Node>
10 分改用unique_ptr,把赋值操作改成移动操作。
push_front的时候要注意不能提前把head move掉,否则会导致后面判断head为空
实现拷贝构造函数为深拷贝 15 分
遍历列表并复制
说明为什么可以删除拷贝赋值函数 5 分
拷贝赋值函数可以由拷贝构造+移动赋值函数实现。
改进
Node
的构造函数 5 分使用explicit和列表表达式
并通过
main()
函数中的基本测试。