Skip to content

Instantly share code, notes, and snippets.

@xwlee
Created July 21, 2023 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xwlee/a9736d59a59b32791f71bc1c7bf12261 to your computer and use it in GitHub Desktop.
Save xwlee/a9736d59a59b32791f71bc1c7bf12261 to your computer and use it in GitHub Desktop.
double-linked-list.js
class Node {
constructor(value) {
this.value = value
this.next = null
this.prev = null
}
}
class DoubleLinkedList {
constructor(value) {
const newNode = new Node(value)
this.head = newNode
this.tail = this.head
this.length = 1
}
push(value) {
const newNode = new Node(value)
if (!this.head) {
this.head = newNode
this.tail = newNode
} else {
this.tail.next = newNode
newNode.prev = this.tail
this.tail = newNode
}
this.length++
return this
}
pop() {
}
}
let myDoubleLinkedList = new DoubleLinkedList(1)
myDoubleLinkedList.push(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment