Skip to content

Instantly share code, notes, and snippets.

@topnotch48
Created November 1, 2018 19:16
Show Gist options
  • Save topnotch48/f11a077b6d0ab8b2379e9bd931335723 to your computer and use it in GitHub Desktop.
Save topnotch48/f11a077b6d0ab8b2379e9bd931335723 to your computer and use it in GitHub Desktop.
private void ReCalculateDown()
{
int index = 0;
while (HasLeftChild(index))
{
var biggerIndex = GetLeftChildIndex(index);
if (HasRightChild(index) && GetRightChild(index) > GetLeftChild(index))
{
biggerIndex = GetRightChildIndex(index);
}
if (_elements[biggerIndex] < _elements[index])
{
break;
}
Swap(biggerIndex, index);
index = biggerIndex;
}
}
private void ReCalculateUp()
{
var index = _size - 1;
while (!IsRoot(index) && _elements[index] > GetParent(index))
{
var parentIndex = GetParentIndex(index);
Swap(parentIndex, index);
index = parentIndex;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment