자료구조, 알고리즘

[자료구조] 큐(Queue) - 자바스크립트로 구현하기

설명 연결 리스트는 삽입과 삭제의 시간 복잡도가 O(1)이다. 따라서 큐를 배열이 아닌 연결리스트로 구현하면 성능상 이점이 있다. 단일 연결 리스트로 구현해서 삽입은 맨 뒤에, 삭제는 맨 앞에서 진행한다. (삭제를 뒤에서 하면 시간이 오래 걸리기 때문이다.) 코드 class Node { constructor(value){ this.value = value; this.next = null; } } class Queue { constructor(){ this.first = null; this.last = null; this.size = 0; } enqueue(val){ var newNode = new Node(val); if(!this.first){ this.first = newNode; this.last ..

리즈(Liz)
'큐' 태그의 글 목록