数组生成单向链表
const createLinkList = (arr = [1,2,3,4,5,6]) => { const length = arr.length; let curNode = { value: arr[arr.length - 1], next: null } for(let i = length -2; i > -1; i--){ curNode = { value: arr[i], next: curNode } } return curNode }
反转单向链表
const reverseLinkList = (linkList = createLinkList()) => { let curNode = { value: linkList.value, next: null } while(linkList.next){ linkList = linkList.next curNode = { value:linkList.value, next:curNode } } return curNode }
标签:linkList,arr,反转,单向,value,next,链表,curNode From: https://www.cnblogs.com/zhenjianyu/p/17067926.html