Skip to content

Riga finished hw2! #61

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Riga finished hw2! #61

wants to merge 1 commit into from

Conversation

Riga27527
Copy link

基本要求都完成了!

  1. 避免函数参数不必要的拷贝

    • print函数传参改成了const List&
  2. 修复智能指针造成的问题

    • 原来使用两个shared_ptr会造成前后两个指针互相需要等待对方析构才能析构,造成死锁导致两个都不能析构,所以有两种解决办法:(本次作业采用后者)
      1. shared_ptr + weak_ptr;
      2. unique_ptr + naive ptr.
  3. 改用 unique_ptr

    • 作业中所有shared_ptr都改成了unique_ptr
  4. 实现拷贝构造函数为深拷贝

    • 此处对原本代码的双向链表 insert 实现很困惑,然后按照自己当时学数据结构的理解重新实现了一遍。深拷贝需要重新逐个Node分配空间。
  5. 说明为什么可以删除拷贝赋值函数

    • 作业中对List赋值的时候,可以转化为首先调用默认构造函数构造临时对象(右值),然后再调用默认的移动构造函数。
  6. 改进 Node 的构造函数

    • 采用初始化列表构造。

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

Successfully merging this pull request may close these issues.

1 participant