public static void Main()
Console.WriteLine(Math.Log(5));
var numArray = new int[5];
var numArrayAsc = new int[5];
for (var i = numArrayAsc.Length -1; i >= 0; i--) {
numArrayAsc[i] = heap.Remove();
foreach (var num in numArrayAsc) {
Console.WriteLine($"Num Array Asc - {num}");
public void Insert(int num) {
throw new InvalidOperationException();
throw new InvalidOperationException();
items[0] = items[--Count];
private int GetLargerChildIndex(int index) {
if (!HasLeftChild(index))
if (!HasRightChild(index))
return LeftChildIndex(index);
LeftChild(index) > RightChild(index) ?
private bool HasLeftChild(int index) {
return LeftChildIndex(index) <= Count;
private bool HasRightChild(int index) {
return RightChildIndex(index) <= Count;
private bool IsValidParent(int index) {
if (!HasLeftChild(index))
var isValid = items[index] >= LeftChild(index);
if (HasRightChild(index))
isValid &= items[index] >= RightChild(index);
private int RightChild(int index) {
return items[RightChildIndex(index)];
private int LeftChild(int index) {
return items[LeftChildIndex(index)];
private int LeftChildIndex(int index) {
private int RightChildIndex(int index) {
private void BubbleUp() {
var newItemIndex = Count - 1;
while (newItemIndex > 0 && items[newItemIndex] > items[GetParentIndex(newItemIndex)]) {
Swap(newItemIndex, GetParentIndex(newItemIndex));
newItemIndex = GetParentIndex(newItemIndex);
private void BubbleDown() {
while (!IsValidParent(index) && index <= Count) {
var largerChildIndex = GetLargerChildIndex(index);
Swap(index, largerChildIndex);
index = largerChildIndex;
return Count == items.Length;
private int GetParentIndex(int index) {
private void Swap(int firstIndex, int secondIndex) {
var temp = items[firstIndex];
items[firstIndex] = items[secondIndex];
items[secondIndex] = temp;
foreach (var item in items) {