[solved]-Cmps 390 Minheapjava Complete 4 Methods Getmin Add Removemin Reheap Public Class Minheap P Q39081313


// CMPS 390 // MinHeap.java // Complete 4 methods: getMin, add, removeMin, reheap public class MinHeap { private Comparable a heap; // array of heap entries private static final int DEFAULT MAX SIZE = 100; private int lastIndex; // index of last entry public MinHeap() { heap = new Comparable (DEFAULT_MAX_SIZE]; lastIndex = 0; } // end default constructor public MinHeap (int maxSize) { heap = new Comparable (maxSize); lastIndex = 0; } // end constructor public MinHeap (Comparable[] entries) { lastIndex = entries.length; heap = new Comparable (lastIndex + 1]; // copy given array to data field for (int index = 0; index < entries.length; index++) heap (index+1] = entries (index]; // create heap for (int index = heap.length/2; index > 0; index–) reheap (index); } // end constructor public Comparable getMin() { Comparable root = null; // ADD YOUR CODE HERE return root; ) // end getMin public boolean isEmpty() { return lastIndex < 1; } // end is Empty public int getSize() { return lastIndex; } // end getSize public void clear() { for (i lastIndex > -1; lastIndex–) heap [last Index] = null; last Index = 0; ) // end clear public void add (Comparable newEntry) { // ADD YOUR CODE HERE } // end add public Comparable removeMin() { Comparable root = null; // ADD YOUR CODE HERE return root; } // end removeMin private void reheap (int root Index) { // ADD YOUR CODE HERE } // end reheap public void display() { int size = getSize(); System.out.println(“nThe Min Heap has ” + size + “items”); for (int i = 1; i <= size; i++) System.out.print (heap[i] + ” “); System.out.println(); } // end display 1 // end MinHeap CMPS 390 // MinHeapDriver.java // Kuo-pao Yang /* s = {“D”, “E”, “I”, “C”, “H”, “A”, “E”, “J”, “B”, “G”}; DGI E The Min Heap has 10 items ABCDGIEJ FH public class MinHeapDriver public static void main(String[] argv) { MinHeap aheap = createMinHeap(); testMinHeapOperations (aHeap); } // end main public static MinHeap createMinHeap() { MinHeap aheap = new MinHeap(); String[] s = {“D”, “F”, “I”, “C”, “H”, “A”, “E”, “J”, “B”, “G”}; System.out.println(“Testing add()”); for (int i=0; i < s.length; i++) { System.out.print (s[i] + ” “); aheap.add (s[i]); aHeap.display(); return aHeap; } // creatMinHeap public static void testMinHeapoperations (MinHeap aheap) System.out.println(“Testing isEmpty() returns = ” + aHeap.isEmpty() + ” (should be false)”); System.out.println(“Testing getMin() returns = ” + aheap.getMin() + ” (should be A) “); System.out.println(“Removing entries in descending order:”); while (! aheap.isEmpty()) System.out.print (aHeap.removeMin() + ” “); System.out.println(” (should be ABCDEFGH I J)”); } // end testMinHepoperations } // end MinHeapDriver /* OUTPUT Testing add() DFICHAEJBG The Min Heap has 10 items ABCDGIEJFH Testing isEmpty() returns = false (should be false) Testing getMin() returns = A (should be A) Removing entries in descending order: ABCDEFGHIJ (should be ABCDEFGHIJ) Show transcribed image text // CMPS 390 // MinHeap.java // Complete 4 methods: getMin, add, removeMin, reheap public class MinHeap { private Comparable a heap; // array of heap entries private static final int DEFAULT MAX SIZE = 100; private int lastIndex; // index of last entry public MinHeap() { heap = new Comparable (DEFAULT_MAX_SIZE]; lastIndex = 0; } // end default constructor public MinHeap (int maxSize) { heap = new Comparable (maxSize); lastIndex = 0; } // end constructor public MinHeap (Comparable[] entries) { lastIndex = entries.length; heap = new Comparable (lastIndex + 1]; // copy given array to data field for (int index = 0; index 0; index–) reheap (index); } // end constructor public Comparable getMin() { Comparable root = null; // ADD YOUR CODE HERE return root; ) // end getMin public boolean isEmpty() { return lastIndex -1; lastIndex–) heap [last Index] = null; last Index = 0; ) // end clear public void add (Comparable newEntry) { // ADD YOUR CODE HERE } // end add public Comparable removeMin() { Comparable root = null; // ADD YOUR CODE HERE return root; } // end removeMin private void reheap (int root Index) { // ADD YOUR CODE HERE } // end reheap public void display() { int size = getSize(); System.out.println(“nThe Min Heap has ” + size + “items”); for (int i = 1; i
Expert Answer
Answer to // CMPS 390 // MinHeap.java // Complete 4 methods: getMin, add, removeMin, reheap public class MinHeap { private Compara… . . .
OR

