Update List.hpp

main
p68710245 1 year ago
parent e7c443d5a6
commit 70c9fb5205

@ -41,7 +41,7 @@ template <typename T>
void List<T>::clear() void List<T>::clear()
{ {
while (head->link) while (head->link)
head->remove_after(); delete head->remove_after();
tail = head; // 务必注意本类当中的操作是否会影响tail tail = head; // 务必注意本类当中的操作是否会影响tail
} }
@ -73,7 +73,8 @@ void List<T>::print() const
Node<T> *tempP{head->link}; Node<T> *tempP{head->link};
while (tempP) while (tempP)
{ {
tempP->print(); //tempP->print();
std::cout << tempP->get_info() << '\t';
tempP = tempP->link; tempP = tempP->link;
} }
std::cout << '\n'; std::cout << '\n';
@ -97,7 +98,7 @@ void List<T>::insert_rear(Node<T> *p)
template <typename T> template <typename T>
Node<T> *List<T>::delete_node(Node<T> *p) Node<T> *List<T>::delete_node(Node<T> *p)
{ {
Node<T> *tempP{head}; // 注意与之前的不同 Node<T> *tempP{head}; // 注意与之前的不同
while (tempP->link && tempP->link != p) // 找到p的位置 while (tempP->link && tempP->link != p) // 找到p的位置
tempP = tempP->link; tempP = tempP->link;
if (p == tail) if (p == tail)

Loading…
Cancel
Save