Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.NoSuchelementException; * An implementation of a heap of integers. public class Heap { // Main method to test this class public static void main(String[]

image text in transcribed
image text in transcribed
image text in transcribed
import java.util.NoSuchelementException; * An implementation of a heap of integers. public class Heap { // Main method to test this class public static void main(String[] args) { } private int[] heap; // Array where elements are stored private int size; 1/ Number of elements in the heap // Constructor - creates an empty heap with capacity 10 public Heap() { this(10); } 1/ Constructor - creates an empty heap with // specified capacity public Heap(int capacity) { heap = new int[capacity); size = 0; } the * Adds the given element to the heap. @param e element to add ethrows IllegalStateException if the heap is full public void add (int e) { if (size == heap.length) throw new IllegalStateException("heap full"); // WRITE ME! } 1/ Given a parent, returns the index of the smaller child, // or -1 if there are no children. // or -1 if there are no children. // This is a private method used by remove() private int smaller(int iParent) { // WRITE ME! return 0; // replace this line } Removes and returns the smallest element in the heap. (which is the element at the top of the heap). * @return smallest element * @throws NoSuchElementException if heap is empty public int remove() { if (size == 0) throw new NoSuchelementException("empty heap"); // WRITE ME! return 0; // replace this line } * Returns true if the given array meets the heap property that each parent is

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago