Task 1
Task 1
Think carefully about how you implement each method, and manage the underlying data.
Performance is critical, so keep cycles and memory usage to a minimum. Be sure to test
your heap with very small and very large values of x. As always, keep a weather eye out for
sneaky edge cases.
Solution
import java.util.Arrays;
import java.util.NoSuchElementException;
// Constructor
public PowerHeap(double x, int capacity) {
this.size = 0;
heapArray = new int[capacity + 1];
this.x = x;
Arrays.fill(heapArray, -1);
}
int i = 0;
while (i < size - 1) {
heapifyUp(i);
i++;
}
return maxItem;
}
heap.print();
heap.print();
}
}
Output