index로 접근할 수 없다.
다음 데이터에 대한 정보를 통해 접근 가능하다.
각 노드는 단지 다음 노드를 가리킬 뿐이다.
Head--------------------------------Tail
[4] =next=> [6] =next=> [8] =next=> [2] =null=>
push
class Node{ constructor(val){ this.val = val; this.next = null; } } class SinglyLinkedList{ constructor(){ this.head = null; this.tail = null; this.length = 0; } push(val){ var newNode = new Node(val); if(!this.head){ this.head = newNode; this.tail = this.head; } else { this.tail.next = newNode; this.tail = newNode; } this.length++; return this; } } var list = new SinglyLinkedList()