反转单向链表
数组生成单向链表
const createLinkList = (array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) => {
let root = null;
for (let index = 0; index < array.length; index++) {
const element = array[index];
const node = {
value: element,
next: null,
};
node.next = root;
root = node;
}
return root;
};
反转单向链表
const reserveLinkList = (root = createLinkList()) => {
let linklist = null;
while (root) {
const node = {
value: root.value,
next: null,
};
node.next = linklist;
linklist = node;
root = root.next;
}
return linklist;
};
以自己现在的努力程度,还没有资格和别人拼天赋

浙公网安备 33010602011771号