Created
July 21, 2023 15:01
-
-
Save xwlee/a9736d59a59b32791f71bc1c7bf12261 to your computer and use it in GitHub Desktop.
double-linked-list.js
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
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