diff --git "a/\346\225\260\346\215\256\347\273\223\346\236\204\345\222\214\347\256\227\346\263\225/linklist.js" "b/\346\225\260\346\215\256\347\273\223\346\236\204\345\222\214\347\256\227\346\263\225/linklist.js" index e69de29..9ebe947 100644 --- "a/\346\225\260\346\215\256\347\273\223\346\236\204\345\222\214\347\256\227\346\263\225/linklist.js" +++ "b/\346\225\260\346\215\256\347\273\223\346\236\204\345\222\214\347\256\227\346\263\225/linklist.js" @@ -0,0 +1,36 @@ +class Node { + constructor(value) { + this.value = value + this.next = null + } +} + +function createList(arr) { + let head = new Node(arr[0]) + let temp = head + for (let i = 1; i < arr.length; i++) { + temp.next = new Node(arr[i]) + temp = temp.next + } + return head +} + +function reverseList(list) { + let arr = [] + let head = list + let temp = head + console.log(temp) + while(temp) { + arr.push(temp.value) + temp = temp.next + } + console.log(arr) + temp = head + + while(temp) { + temp.value = arr.pop() + temp = temp.next + } + + return head +} \ No newline at end of file