JS 알고리즘 15일차 - 이중 연결 리스트(get, set)


JS 알고리즘 15일차 - 이중 연결 리스트(get, set)

Get 소개 입력된 인덱스 위치에 있는 노드를 출력한다. 의사코드 인덱스가 유효한지 확인한다. 인덱스가 유효하면 인덱스가 리스트 길이의 절반보다 작거나 같은지 확인한다. 반보다 작거나 같으면 처음부터 시작하고 크면 뒤에서부터 시작한다. 코드 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; } get(index) { let current = null; if (index < 0 || index >= this.length) return false; if (index <= this.length / 2) { current = this.head; let count = 0; while (count !== index) { c...


#get #JavaScript #set #알고리즘 #연결리스트 #이중연결리스트 #자료구조

원문링크 : JS 알고리즘 15일차 - 이중 연결 리스트(get, set)