Skip to content

Instantly share code, notes, and snippets.

@BogdanAriton
Created June 15, 2021 15:21
Show Gist options
  • Save BogdanAriton/7ec78bf94a5b7e47277fb3f7413d21bc to your computer and use it in GitHub Desktop.
Save BogdanAriton/7ec78bf94a5b7e47277fb3f7413d21bc to your computer and use it in GitHub Desktop.
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