Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone please make a Binarytree of these methodes?: public void add(int ele

ID: 3636620 • Letter: C

Question

Can someone please make a Binarytree of these methodes?:
public void add(int element)
//Adds the specified element into this datastructure.

public void clear()
//Removes all of the elements from this datastructure.

public boolean contains(int element)
//Tests if the specified element is a component in this datastructure.

public int[] inOrder()
//Returns an array containing all of the elements in this datastructure inorder.

public int[] postOrder()
Returns an array containing all of the elements in this datastructure postorder.

public int[] preOrder()
Returns an array containing all of the elements in this datastructure preorder.

public void remove(int element)
Removes the specified element from this datastructure.

public int size()
Returns the number of components in this datastructure.

public int[] toArray()
Returns an array containing all of the elements in this datastructure inorder.

String toString()
Returns a string representation of this datastructure, containing the String representation of each element inorder

Explanation / Answer

public class BinaryHeap implements PriorityQueue { /** * Construct the binary heap. */ public BinaryHeap( ) { currentSize = 0; array = new Comparable[ DEFAULT_CAPACITY + 1 ]; } /** * Construct the binary heap from an array. * @param items the inital items in the binary heap. */ public BinaryHeap( Comparable [ ] items ) { currentSize = items.length; array = new Comparable[ items.length + 1 ]; for( int i = 0; i 0; i-- ) percolateDown( i ); } /** * Test if the priority queue is logically empty. * @return true if empty, false otherwise. */ public boolean isEmpty( ) { return currentSize == 0; } /** * Returns size. * @return current size. */ public int size( ) { return currentSize; } /** * Make the priority queue logically empty. */ public void makeEmpty( ) { currentSize = 0; } private static final int DEFAULT_CAPACITY = 100; private int currentSize; // Number of elements in heap private Comparable [ ] array; // The heap array /** * Internal method to percolate down in the heap. * @param hole the index at which the percolate begins. */ private void percolateDown( int hole ) { int child; Comparable tmp = array[ hole ]; for( ; hole * 2