68template<
typename Node>
69LinkedListNode<Node>::LinkedListNode() : next_node(nullptr), prev_node(nullptr)
73template<
typename Node>
74LinkedList<Node>::LinkedList() : head(nullptr), tail(nullptr), size(0)
78template<
typename Node>
79LinkedList<Node>::~LinkedList()
81 Node* node = this->head;
82 while (node !=
nullptr) {
83 Node* to_be_deleted = node;
84 node = node->next_node;
89template<
typename Node>
90template<
typename... Args>
93 Node* new_node =
new Node(std::forward<Args>(args)...);
95 if (this->
head ==
nullptr) {
96 this->
head = new_node;
97 this->
tail = new_node;
100 this->
tail->next_node = new_node;
101 new_node->prev_node = this->
tail;
102 this->
tail = new_node;
106template<
typename Node>
109 if (node ==
nullptr || !this->
size) {
116 this->
head =
nullptr;
117 this->
tail =
nullptr;
120 Node* to_be_deleted = node;
122 if (node == this->
head) {
124 this->
head->prev_node =
nullptr;
125 delete to_be_deleted;
129 if (node == this->
tail) {
131 this->
tail->next_node =
nullptr;
132 delete to_be_deleted;
136 node->prev_node->next_node = node->next_node;
137 node->next_node->prev_node = node->prev_node;
138 delete to_be_deleted;
141template<
typename Node>
144 if (node ==
nullptr || !this->
size) {
150 this->
head =
nullptr;
151 this->
tail =
nullptr;
152 }
else if (node == this->
head) {
155 this->
head->prev_node =
nullptr;
156 }
else if (node == this->
tail) {
159 this->
tail->next_node =
nullptr;
162 node->prev_node->next_node = node->next_node;
163 node->next_node->prev_node = node->prev_node;