Question: I need help with defining my Comparator cmp to use in other methods in class heap. the comparator uses the ArrayList tree /** * A

I need help with defining my Comparator cmp to use in other methods in class heap. the comparator uses the ArrayList tree

/**

* A complete tree stored in an array list representing this

* binary heap

*/

public ArrayList tree;

/**

* A comparator lambda function that compares two elements of this

* heap when rebuilding it; cmp.compare(x,y) gives 1. negative when x less than y

* 2. positive when x greater than y 3. 0 when x equal y

*/

private Comparatorsuper E> cmp;

cmp =fn

/**

* Constructs an empty heap using the compareTo method of its data type as the

* comparator

*/

public Heap() {

tree = new ArrayList();

}

/**

* A parameterized constructor that uses an externally defined comparator

* @param fn - a trichotomous integer value comparator function

*/

public Heap(Comparatorsuper E> fn) {

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!