Skip to content

Instantly share code, notes, and snippets.

@lykkin
Created April 27, 2018 05:32
Show Gist options
  • Save lykkin/5318f4e57e5a2877bcb77e52961fc368 to your computer and use it in GitHub Desktop.
Save lykkin/5318f4e57e5a2877bcb77e52961fc368 to your computer and use it in GitHub Desktop.
i will never fibb
var min = this._data.findMinimum()
var data = []
var iterationNodes = [min]
var iterationHeads = [min]
var depth = 0
if (min) {
var current
while (depth >= 0) {
current = iterationNodes[depth]
data.push(current.value)
iterationNodes[depth] = current.next
if (current.child) {
++depth
iterationHeads[depth] = iterationNodes[depth] = current.child
} else {
while (depth >= 0 && iterationNodes[depth] === iterationHeads[depth]) {
--depth
}
}
}
}
return data
var nodes = []
var min = this._data.findMinimum()
if (min) {
serializeHeap(min, nodes)
}
return nodes
function serializeHeap(head, arr) {
var current = head
do {
arr.push(current.value)
if (current.child) {
serializeHeap(current.child, arr)
}
current = current.next
} while (current !== head)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment