linked_list.cpp

The linked list is a data structure used for holding a sequence of values, which can be added, removed and displayed.

  1. namespace: 定义命名空间,防止变量混淆。
  2. std::shared_ptr name; shared_ptr: 共享指针,支持多个指针指向同一个元素,当元素没有指针指向,则自动释放内存,核心是指针计数器。
  3. explicit: 修饰单参数构造函数,防止隐式类型转换,不能使用”=”进行构造。
  4. std::make_shared(); make_shared: 性能更佳的返回shared_ptr。无法使用私有的构造函数,如果是私有的,必须手动使用new;不支持自定义删除器。
  5. shared_ptr.reset(): 将指针重置为空状态,减小该指针所管理对象的引用计数,当引用计数变为0,释放所管理的内存对象。

node.hpp