严格使用for循环

时间:2018-04-26 18:41:46

标签: javascript node.js for-loop linked-list frontend

所以,我已经知道如何使用递归来做到这一点。但是,我想严格使用for循环创建我的单链表。我需要写ansList然后ansList.next然后ansList.next.next ...等我想要这样的东西)

let ansList = new ListNode(ansArr[0]);
let n = next;
for (let i =1; i<=ansArr.length;i++) {      
    let x = ansList + n**i;
    x = new ListNode(ansArr[i]);
    };

1 个答案:

答案 0 :(得分:0)

ListNode = function(parent)
{
  this.parent = parent;
}

var first = new ListNode();
var next = first;
for (let i =1; i<=10;i++)
      next = new ListNode(next);

console.log(next);