Created
April 27, 2018 05:32
-
-
Save lykkin/5318f4e57e5a2877bcb77e52961fc368 to your computer and use it in GitHub Desktop.
i will never fibb
This file contains 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
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 |
This file contains 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
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