This codes not complie it can you fix the code can complie it?   import java.util.ArrayList; public class Heap { void heapify(ArrayList hT, int i) { int size = hT.size(); int largest = i; int l = 2 * i + 1; int r = 2 * i + 2; if (l < size && hT.get(l) > hT.get(largest)) largest = l; if (r < size && hT.get(r) > hT.get(largest)) largest = r; if (largest != i) { int temp = hT.get(largest); hT.set(largest, hT.get(i)); hT.set(i, temp); heapify(hT, largest); } } void insert(ArrayList hT, int newNum) {     int size = hT.size();     if (size == 0) {     hT.add(newNum);     } else {     hT.add(newNum);     for (int i = size / 2 - 1; i >= 0; i--) {     heapify(hT, i);     }     }     }     void deleteNode(ArrayList hT, int num) {         int size = hT.size();         int i;         for (i = 0; i < size; i++) {         if (num == hT.get(i))         break;         }                 int temp = hT.get(i);         hT.set(i, hT.get(size-1));         hT.set(size-1, temp);                 hT.remove(size-1);         for (int j = size / 2 - 1; j >= 0; j--) {         heapify(hT, j);         }         }                 void printArray(ArrayList array, int size) {         for (Integer i : array) {         System.out.print(i + " ");         } class Main{     public static void main(String args[]) {         ArrayList array = new ArrayList();         int size = array.size();         Heap h = new Heap();         h.insert(array, 3);         h.insert(array, 4);         h.insert(array, 9);         h.insert(array, 5);         h.insert(array, 2);         System.out.println("Max-Heap array: ");         h.printArray(array, size);         h.deleteNode(array, 4);         System.out.println("After deleting an element: ");         h.printArray(array, size);     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
This codes not complie it can you fix the code can complie it?
 
import java.util.ArrayList;

public class Heap {
void heapify(ArrayList hT, int i) {
int size = hT.size();
int largest = i;
int l = 2 * i + 1;
int r = 2 * i + 2;
if (l &lt; size &amp;&amp; hT.get(l) &gt; hT.get(largest))
largest = l;
if (r &lt; size &amp;&amp; hT.get(r) &gt; hT.get(largest))
largest = r;

if (largest != i) {
int temp = hT.get(largest);
hT.set(largest, hT.get(i));
hT.set(i, temp);

heapify(hT, largest);
}
}
void insert(ArrayList hT, int newNum) {
    int size = hT.size();
    if (size == 0) {
    hT.add(newNum);
    } else {
    hT.add(newNum);
    for (int i = size / 2 - 1; i &gt;= 0; i--) {
    heapify(hT, i);
    }
    }
    }
    void deleteNode(ArrayList hT, int num) {
        int size = hT.size();
        int i;
        for (i = 0; i &lt; size; i++) {
        if (num == hT.get(i))
        break;
        }
       
        int temp = hT.get(i);
        hT.set(i, hT.get(size-1));
        hT.set(size-1, temp);
       
        hT.remove(size-1);
        for (int j = size / 2 - 1; j &gt;= 0; j--) {
        heapify(hT, j);
        }
        }
       
        void printArray(ArrayList array, int size) {
        for (Integer i : array) {
        System.out.print(i + " ");
        }
class Main{
    public static void main(String args[]) {
        ArrayList array = new ArrayList();
        int size = array.size();
        Heap h = new Heap();
        h.insert(array, 3);
        h.insert(array, 4);
        h.insert(array, 9);
        h.insert(array, 5);
        h.insert(array, 2);
        System.out.println("Max-Heap array: ");
        h.printArray(array, size);
        h.deleteNode(array, 4);
        System.out.println("After deleting an element: ");
        h.printArray(array, size);
    }
}
Heap data structure called to be a complete binary tree while maintaining the heap property,
where given node is
always greater than its child node/s and the key of the root node is the largest
among all other nodes. This property is also called max heap property.
always smaller than the child node/s and the key of the root node is the smallest
among all other nodes. This property is also called min heap property.
You are given a code with Pseudo code. Knowing the properties from the Chapter, write the
logic for following methos- heapify, insert, deleteNode
import java.util.ArrayList;
public class Heap {
Max Heap Lab
void heapify(ArrayList<Integer> hT, int i) {
/* Heapify(array, size, i)
set i as largest
leftChild 21 + 1
rightChild 21 + 2
*/
}
void
*/
if leftChild > array [largest]
set leftChildIndex as largest
if rightChild > array[largest]
set rightChild Index as largest
swap array[i] and array [largest]
To create a Max-Heap:
}
void insert (ArrayList<Integer> hT, int newNum) {
/* If there is no node,
MaxHeap (array, size)
loop from the first index of non-leaf node down to zero.
call heapify
create a newNode.
else (a node is already present)
insert the newNode at the end (last node from left to right.)
heapify the array
deleteNode(ArrayList<Integer> hT, int num) {
/* If nodeToBeDeleted is the leafNode
remove the node
Else swap nodeToBeDeleted with the lastLeafNode
remove noteToBeDeleted
heapify the array
}
void printArray(ArrayList<Integer> array, int size) {
3
+
Transcribed Image Text:Heap data structure called to be a complete binary tree while maintaining the heap property, where given node is always greater than its child node/s and the key of the root node is the largest among all other nodes. This property is also called max heap property. always smaller than the child node/s and the key of the root node is the smallest among all other nodes. This property is also called min heap property. You are given a code with Pseudo code. Knowing the properties from the Chapter, write the logic for following methos- heapify, insert, deleteNode import java.util.ArrayList; public class Heap { Max Heap Lab void heapify(ArrayList<Integer> hT, int i) { /* Heapify(array, size, i) set i as largest leftChild 21 + 1 rightChild 21 + 2 */ } void */ if leftChild > array [largest] set leftChildIndex as largest if rightChild > array[largest] set rightChild Index as largest swap array[i] and array [largest] To create a Max-Heap: } void insert (ArrayList<Integer> hT, int newNum) { /* If there is no node, MaxHeap (array, size) loop from the first index of non-leaf node down to zero. call heapify create a newNode. else (a node is already present) insert the newNode at the end (last node from left to right.) heapify the array deleteNode(ArrayList<Integer> hT, int num) { /* If nodeToBeDeleted is the leafNode remove the node Else swap nodeToBeDeleted with the lastLeafNode remove noteToBeDeleted heapify the array } void printArray(ArrayList<Integer> array, int size) { 3 +
}
}
for (Integer i : array) {
System.out.print(i + " ");
}
}
System.out.println();
public static void main(String args[]) {
ArrayList<Integer> array = new ArrayList<Integer>();
int size = array.size();
Heap h = new Heap();
h.insert (array, 3);
h.insert (array, 4);
h.insert (array, 9);
h.insert (array, 5);
h.insert (array, 2);
System.out.println("Max-Heap array: ");
h.printArray(array, size);
h.deleteNode (array, 4);
System.out.println("After deleting an element: ");
h.printArray(array, size);
Put all your work in ONE Zip file and submit it in Canvas.
Zip filename should be in format of FirstLast_Lab6.zip (ex. John Doe_Lab6.zip)
Zip file should contain 2 files only:
(1) Heap.java
(2) Output.docx (screenshot of input and output)
< ~\3 >
A
Transcribed Image Text:} } for (Integer i : array) { System.out.print(i + " "); } } System.out.println(); public static void main(String args[]) { ArrayList<Integer> array = new ArrayList<Integer>(); int size = array.size(); Heap h = new Heap(); h.insert (array, 3); h.insert (array, 4); h.insert (array, 9); h.insert (array, 5); h.insert (array, 2); System.out.println("Max-Heap array: "); h.printArray(array, size); h.deleteNode (array, 4); System.out.println("After deleting an element: "); h.printArray(array, size); Put all your work in ONE Zip file and submit it in Canvas. Zip filename should be in format of FirstLast_Lab6.zip (ex. John Doe_Lab6.zip) Zip file should contain 2 files only: (1) Heap.java (2) Output.docx (screenshot of input and output) < ~\3 > A
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

        at Main.main(Heap.java:66)

 

what this mean is?

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Operations of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education