How do I fix these WARNINGS (not errors) that I am getting? import java.util.*;
ID: 3621617 • Letter: H
Question
How do I fix these WARNINGS (not errors) that I am getting?import java.util.*;
public class MyMinHeap
{
private Object[] theHeap;
private int size;
public MyMinHeap()
{
theHeap = new Object[6];
size = 0;
buildHeap();
}
public MyMinHeap(int cap)
{
theHeap = new Object[(cap)];
size = cap + 1;
}
public MyMinHeap(Object[] arr, int n)
{
size = n;
theHeap = arr;
buildHeap();
}
public int getSize()
{
return theHeap.length;
}
public boolean add(Object o)
{
if((o==null)||(size>= theHeap.length))
return false;
theHeap[size] = o;
shiftDown(size++);
return true;
}
public Object removeMin()
{
if(size <= 0)
return null;
swap(0,--size);
shiftUp(0);
return theHeap[size];
}
public void parse()
{
int i;
for(i=0;i<size;i++)
{
System.out.println(theHeap[i].toString());
}
}
private void buildHeap()
{
int i;
for(i = size/2 -1; i>=0; i--)
shiftUp(i);
}
private int shiftUp(int i)
{
int p; if ((i > 0) && (i < size))
{
p = parent(i);
if (((Comparable)theHeap[i]).compareTo(theHeap[p]) > 0)
{
swap(p, i);
return shiftUp(p);
}
}
return i;
}
private void shiftDown(int i)
{
int lc;
if ((i >= 0) && (i < (size / 2)))
{
lc = 2 * i + 1; // left child
if (((lc + 1) < size) && (((Comparable)theHeap[lc + 1]).compareTo(theHeap[lc]) > 0))
lc++; // rc was larger // now lc is index of “largest” child
if (((Comparable)theHeap[lc]).compareTo(theHeap[i]) > 0)
{
swap(lc, i); // lc was larger, so shift
shiftDown(lc); // keep shifting
}
}
}
private int parent(int i)
{
if(i == 0)
return -1;
return (i-1)/2;
}
private int leftChild(int i)
{
return 2*i + 1;
}
private int rightChild(int i)
{
return 2*(i+1);
}
private void swap(int a, int b)
{
Object temp;
temp = theHeap[a];
theHeap[a] = theHeap[b];
theHeap[b] = temp;
}
}
Explanation / Answer
I UNDERSTAND. DONT ANSWER THIS!
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.