You are viewing a single comment's thread. Return to all comments →
Scala, with recursion:
def reverse(llist: SinglyLinkedListNode): SinglyLinkedListNode = { @tailrec def reverseNode(node: SinglyLinkedListNode, next: SinglyLinkedListNode): SinglyLinkedListNode = { if (node == null) next else { val prev = node.next node.next = next reverseNode(prev, node) } } reverseNode(llist, null) }
Seems like cookies are disabled on this browser, please enable them to open this website
Reverse a linked list
You are viewing a single comment's thread. Return to all comments →
Scala, with recursion: