Skip to content

Instantly share code, notes, and snippets.

@vadimkorr
Last active March 10, 2018 19:42
Show Gist options
  • Save vadimkorr/a7ec44785e06e88d31885c9620384559 to your computer and use it in GitHub Desktop.
Save vadimkorr/a7ec44785e06e88d31885c9620384559 to your computer and use it in GitHub Desktop.
function dll() {
this.head = null
}
dll.prototype.push = function(val) {
let head = this.head, curr = head, prev = head
if (!head) this.head = { val: val, prev: null, next: null }
else {
while (curr && curr.next) {
prev = curr
curr = curr.next
}
curr.next = { val: val, prev: curr, next: null }
}
}
// output
dll.prototype.print = function() {
let curr = this.head
while(curr) {
console.log(curr.val)
curr = curr.next
}
}
// input
let adll = new dll()
adll.push(2)
adll.push(5)
adll.push(7)
adll.push(9)
adll.push(10)
let bdll = new dll()
bdll.push(1)
bdll.push(3)
bdll.push(8)
bdll.push(10)
bdll.push(11)
bdll.push(15)
cdll.print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment