Last active
August 23, 2023 09:41
-
-
Save zlrlo/43fa330c95fb033c11931d0f6a46753b to your computer and use it in GitHub Desktop.
[JS] Queue javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // LinkedList | |
| class Node { | |
| constructor(value) { | |
| this.value = value; | |
| this.next = null; | |
| } | |
| } | |
| class Queue { | |
| constructor() { | |
| this.head = null; | |
| this.tail = null; | |
| this.size = 0; | |
| } | |
| push(value) { | |
| const newNode = new Node(value); | |
| if(this.head === null) { | |
| this.head = this.tail = newNode; | |
| this.size += 1; | |
| } | |
| else { | |
| this.tail.next = newNode; | |
| this.tail = newNode; | |
| } | |
| } | |
| pop() { | |
| const returnValue = this.head.value; | |
| this.head = this.head.next; | |
| this.size -= 1; | |
| return returnValue; | |
| } | |
| front() { | |
| return this.head.value; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
shift 사용하지 말 것 - O(n)