void reverse()
{
if (head == nullptr || head->next == nullptr)
return;
Node* prevNode = nullptr;
Node* currentNode = head;
while (currentNode != nullptr)
{
prevNode = currentNode;
currentNode = currentNode->next;
prevNode->next = prevNode->prev;
prevNode->prev = currentNode;
}
head = prevNode;
}
I want to know if the logic of this code is correct.
I have done much research, but I didn’t find the same logic as for
thank you.
New contributor
Djamel Slimani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.