Created
June 15, 2021 15:21
-
-
Save BogdanAriton/7ec78bf94a5b7e47277fb3f7413d21bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void reverse() noexcept | |
{ | |
// to reverse the list we simply have to switch the nodes until the head becomes the tail | |
node_ptr current; | |
current = std::move(head); | |
node_ptr next = nullptr; | |
node_ptr temp = nullptr; | |
while (current != nullptr) | |
{ | |
next = std::move(current->next); | |
current->next = std::move(temp); | |
temp = std::move(current); | |
current = std::move(next); | |
} | |
head = std::move(temp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment