Shift 소개 맨 앞에서 노드를 하나 제거한다. 의사코드 리스트가 비어있다면 undefined를 반환한다. 그렇지 않다면 head를 변수에 저장한다. 현재 head를 제거하고 길이를 1 감소시킨다. 만약 길이가 1인 상태에서 제거한다면 head와 tail을 모두 null로 변경한다. 코드 class Node { constructor(val) { this.val = val; this.next = null; this.prev = null; } } class DoublyLinkedList { constructor() { this.head = null; this.tail = null; this.length = 0; } shift() { if (!this.head) return undefined; const oldHead = this.head; if (this.length === 1) { this.head = null this.tail = null } else { this.head = ol...
#JavaScript
#shift
#unshift
#알고리즘
#연결리스트
#이중연결리스트
#자료구조
원문링크 : JS 알고리즘 15일차 - 이중 연결 리스트(shift, unshift)