Skip to content

Instantly share code, notes, and snippets.

@zlrlo
Last active August 23, 2023 09:41
Show Gist options
  • Select an option

  • Save zlrlo/43fa330c95fb033c11931d0f6a46753b to your computer and use it in GitHub Desktop.

Select an option

Save zlrlo/43fa330c95fb033c11931d0f6a46753b to your computer and use it in GitHub Desktop.
[JS] Queue javascript
// 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;
}
}
@zlrlo
Copy link
Author

zlrlo commented Jan 9, 2023

shift 사용하지 말 것 - O(n)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment