//sort tile lower into heap void SortDown(MovementTile item) { while (true) { int leftChildIndex = item.heapIndex * 2 + 1; int rightChildIndex = (item.heapIndex * 2) + 2; int swapIndex = 0; if (leftChildIndex < itemCount) { swapIndex = leftChildIndex; if (rightChildIndex < itemCount) { if (heapTiles [leftChildIndex].CompareTo(heapTiles [rightChildIndex]) < 0) { swapIndex = rightChildIndex; } } if (item.CompareTo(heapTiles [swapIndex]) < 0) { Swap(item, heapTiles [swapIndex]); } else { return; } } else { return; } } }
//sort item higher into heap void SortUp(MovementTile item) { int indexOfParent = (item.heapIndex - 1) / 2; while (true) { MovementTile parent = heapTiles [indexOfParent]; if (item.CompareTo(parent) > 0) { Swap(item, parent); } else { break; } indexOfParent = (item.heapIndex - 1) / 2; } }