function Node(value) {
this.value = value;
this.next = null;
}
const node1 = new Node(1);
const node2 = new Node(2);
const node3 = new Node(3);
const node4 = new Node(4);
const node5 = new Node(5);
node1.next = node2;
node2.next = node3;
node3.next = node4;
node4.next = node5;
function reverse(node) {
if (node.next.next === null) {
node.next.next = node;
return node.next;
} else {
const result = reverse(node.next);
node.next.next = node;
node.next = null;
return result;
}
}
const newNode = reverse(node1);
function diguiLink(node) {
let tempNode = node;
if (tempNode === null) return;
console.log(tempNode.value);
diguiLink(tempNode.next);
}
diguiLink(newNode);
console