diff options
-rw-r--r-- | list.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -15,7 +15,7 @@ struct List ~List() { - if (next == NULL) + if (next == nullptr) return; delete next; } @@ -25,31 +25,31 @@ template <typename T> List<T> *append(List<T> *lst, T value) { List<T> *node; - if (lst == NULL) + if (lst == nullptr) { node = new List<T>; node->value = value; - node->next = NULL; + node->next = nullptr; return node; } - for (node = lst; node->next != NULL; node = node->next) + for (node = lst; node->next != nullptr; node = node->next) continue; node->next = new List<T>; node->next->value = value; - node->next->next = NULL; + node->next->next = nullptr; return lst; } /** Reverse a list */ template <typename T> -List<T> *reverse(List<T> *lst, List<T> *prev = NULL) +List<T> *reverse(List<T> *lst, List<T> *prev = nullptr) { auto next = lst->next; lst->next = prev; - if (next == NULL) + if (next == nullptr) return lst; return reverse(next, lst); } @@ -65,7 +65,7 @@ std::ostream& operator<<(std::ostream& ostream, const List<T> *lst) int main(void) { - auto lst = append<int>(NULL, 1); + auto lst = append<int>(nullptr, 1); for (int i = 2; i < 10; ++i) lst = append(lst, i); std::cout << lst << std::endl; |