linked list1 코딩테스트 대비 자료구조 Javascript 구현 1. Queue shift() 등을 사용하면 O(N)의 시간복잡도를 가지기 때문에 Linked List를 활용하여 O(1)로 구현 class Node { constructor(data) { this.data = data; this.next = null; } } // 큐 클래스 class Queue { constructor() { this.head = null; // 제일 앞 노드 this.rear = null; // 제일 뒤 노드 this.length = 0; // 노드의 길이 } enqueue(data) { // 노드 추가. const node = new Node(data); // data를 가진 node를 만들어준다. if (!this.head) { // 헤드가 없을 경우 head를 해당 노드로 th.. 2022. 6. 13. 이전 1 다음