We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Reverse a linked list
Reverse a linked list
Sort by
recency
|
894 Discussions
|
Please Login in order to post a comment
Here is my c++ solution, you can watch video explanation here : https://youtu.be/F4nGusqPIu0
SinglyLinkedListNode* reverse(SinglyLinkedListNode* llist) { SinglyLinkedListNode* prev = NULL; SinglyLinkedListNode* current = llist; SinglyLinkedListNode* next = NULL; while (current != NULL) { next = current->next; current->next = prev; prev = current; current = next; } return prev;
}
SinglyLinkedListNode* reverse(SinglyLinkedListNode* llist) { SinglyLinkedListNode* prev = NULL; SinglyLinkedListNode* current = llist; SinglyLinkedListNode* next = NULL;
}
Easiest Solution with c#
just remove the Class and public The final solution is: