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
|
888 Discussions
|
Please Login in order to post a comment
SinglyLinkedListNode* reverse(SinglyLinkedListNode* head) {
}
Here is my c++ solution, you can watch video explanation here : https://youtu.be/F4nGusqPIu0
public static SinglyLinkedListNode reverse(SinglyLinkedListNode llist) { // Write your code here SinglyLinkedListNode privous=null; SinglyLinkedListNode current=llist; SinglyLinkedListNode following=llist; while(current!=null){ following=following.next; current.next=privous; privous=current; current=following; } return privous;
}
Kotlin code to pretty print is broken for test cases with more than 1 test. Example, for custom test:
Result is:
It needs a break line between pretty prints