

random access 가능
⇒ 배열의 n번째 원소 방문시 O(1)
시간으로 가능 예) arr[3]
random access 불가능
⇒ 리스트의 n번째 노드 방문시 O(n)시간소요
예) head 노드부터 n번째 노드까지 순회
원소 삽입 & 삭제 일반적으로 O(n) 시간 소요
배열보다 빨라질 수 있는 노드 삽입 & 삭제




const list = {
  head : {
    value : 90,
    next : {
      value : 10,
      next : {
        value : 89,
        next : {
          value : 100,
          next : null
        }
      }
    }
  }
}
class Node {
  constructor(data){
    this.data = data;
    this.next = null;
  }
}
class LinkedList {
  constructor() {
    let init = new Node("init")
    this.head = init;
    this.next = init;
    this.현재노드 = undefined;
    this.데이터수 = 0;
  }
  length() {
    return this.데이터수
  }
  append(date) {
    let 새로운노드 = new Node(data);
    this.tail.next = 새로운노드;
    this.tail = 새로운노드;
    this.데이터수 += 1; 
  }
  toString() {
    let 순회용현재노드 = this.head;
    순회용현재노드 = 순회용현재노드.next;
    let s ="";
    for (let i = 0; i < this.데이터수; i++){
      s += `${순회용현재노드.data}, `
      순회용현재노드 = 순회용현재노드.next;
    }
    return `[${s.slice(0, -2)}]`;
  }
    get fullData(){
      let 순회용현재노드 = this.head;
      순회용현재노드 = 순회용현재노드.next;
  
      let s ="";
      for (let i = 0; i < this.데이터수; i++){
        s += `${순회용현재노드.data}, `
        순회용현재노드 = 순회용현재노드.next;
      }
      return JSON.parse(`[${s.slice(0, -2)}]`);
    }
   inset(index, data) {
    let 순회용현재노드 = this.head;
    순회용현재노드 = 순회용현재노드.next;
    for (let i = 0; i < index - 1; i++){
      순회용현재노드 = 순회용현재노드.next;
    }
    let 새로운노드 = new Node(data);
    새로운노드.next = 순회용현재노드.next;
    순회용현재노드.next = 새로운노드;
    this.데이터수 += 1;
  }
   
}
a = new LinkedList();
a.append(1);
a.append(2);
a.append(3);
a.append(10);
a.append(30);
a.append(20);
console.log(a.length())
console.log(1)