Skip to content

complete hw02 && 尝试支持了迭代器 #56

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

BruceChenQAQ
Copy link

  • 避免函数参数不必要的拷贝 5 分

    • 修改为 void print(List &lst)
  • 修复智能指针造成的问题 10 分

  • 改用 unique_ptr<Node> 10 分

    • 修改为使用std::unique_ptr<Node> next;struct Node* prev;
    • 当链表的头节点被解构,会导致其next指针指向的节点被解构,直至整个链表的节点都被解构。
  • 实现拷贝构造函数为深拷贝 15 分

    • 具体实现见代码。
  • 说明为什么可以删除拷贝赋值函数 5 分

    • 因为这相当于使用拷贝构造函数就地构造出对象,从而进一步调用移动赋值函数完成整个过程。
    • 如果使用 explicit 关键词修饰拷贝构造函数,则会产生编译错误。
  • 改进 Node 的构造函数 5 分

    • 使用 explicit 进行修饰。
    • 使用初始化表达式,避免重复初始化。
  • 为了高效率的支持获取 end 迭代器,添加了一个位于链表尾部之后的尾指针。

@miaomiao1992
Copy link

说明为什么可以删除拷贝赋值函数?
我看main函数里面,没有调用拷贝赋值,所以删除也没事。

UP的回答没看懂

因为这相当于使用拷贝构造函数就地构造出对象,从而进一步调用移动赋值函数完成整个过程。
如果使用 explicit 关键词修饰拷贝构造函数,则会产生编译错误。

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants