NVIDIA Interview Question
Software Engineer / DevelopersTested and working code, should take care of edge case tests.
Node MakeSingleLinkedListReverse(Node currentNode)
{
Node previousNode = null;
Node nextNode = null;
while (currentNode != null)
{
nextNode = currentNode.NextNode;
currentNode.NextNode = previousNode;
previousNode = currentNode;
currentNode = nextNode;
}
return previousNode;
}
struct node *head, *reverse, *second;
- Rahul September 21, 2009\\assign head to the head of the linked list
head = top; \\where top already points to the first node
reverse = second = null;
while(head != null){
second = head->next;
head->next = reverse;
reverse = head;
head = second;
}