js combine linked list code example
Example 1: reverse a linked list javascript
// O(n) time & O(n) space
function reverse(head) {
if (!head || !head.next) {
return head;
}
let tmp = reverse(head.next);
head.next.next = head;
head.next = undefined;
return tmp;
}
Example 2: iterate trough linked list java
#Enhances For Loop
for (String temp : linkedList) {
System.out.println(temp);
}