confission
Programmer
i keep getting the following error. it says it's found an int, but the heap is made up of Comparables, so i don't get it.
WorstFit.java:36: inconvertible types
found : int
required: java.lang.Comparable
if ((Comparable)(new Integer(s)).compareTo(myHeap.heap[1])<=0)
(the "^" is pointing at the "(" after "compareTo"
here's the code, if it helps:
package dataStructures;
import java.util.*;
public class WorstFit
{
//s <= c for all i
public static void worstFitPack(int []s, int c)
{
//output packing information one by one
int j=1;
MaxHeap myHeap=new MaxHeap(s.length);
if (s[1]>c)
{
throw new IllegalArgumentException("an element in the array is bigger than the capacity of the containers"
}
myHeap.put((Comparable)(new Integer(s[1])));
for (int i=2; i<s.length; i++)
{
if (s>c)
{
throw new IllegalArgumentException("an element in the array is bigger than the capacity of the containers"
}
if ((Comparable)(new Integer(s)).compareTo(myHeap.heap[1])<=0)
{
Comparable previousAmount=myHeap.heap[1];
MyHeap.put((Comparable)((int)myHeap.removeMax())-((int)element));
System.out.println(+element[1] +"is added to container with " +previousAmount +". container now holds " +myHeap.heap[1]);
}
else
{
myHeap.put((Comparable)(c-((int)(element))));
System.out.println("new container holds " +element);
}
}
}
// test
public static void main(String []args)
{
int n = 10;
int c = 99;
int [] s = {0, 22, 84, 97, 47, 20, 64, 43, 11, 56, 96}; //s[0] is not used
WorstFit.worstFitPack(s, c);
}
}
WorstFit.java:36: inconvertible types
found : int
required: java.lang.Comparable
if ((Comparable)(new Integer(s)).compareTo(myHeap.heap[1])<=0)
(the "^" is pointing at the "(" after "compareTo"
here's the code, if it helps:
package dataStructures;
import java.util.*;
public class WorstFit
{
//s <= c for all i
public static void worstFitPack(int []s, int c)
{
//output packing information one by one
int j=1;
MaxHeap myHeap=new MaxHeap(s.length);
if (s[1]>c)
{
throw new IllegalArgumentException("an element in the array is bigger than the capacity of the containers"
}
myHeap.put((Comparable)(new Integer(s[1])));
for (int i=2; i<s.length; i++)
{
if (s>c)
{
throw new IllegalArgumentException("an element in the array is bigger than the capacity of the containers"
}
if ((Comparable)(new Integer(s)).compareTo(myHeap.heap[1])<=0)
{
Comparable previousAmount=myHeap.heap[1];
MyHeap.put((Comparable)((int)myHeap.removeMax())-((int)element));
System.out.println(+element[1] +"is added to container with " +previousAmount +". container now holds " +myHeap.heap[1]);
}
else
{
myHeap.put((Comparable)(c-((int)(element))));
System.out.println("new container holds " +element);
}
}
}
// test
public static void main(String []args)
{
int n = 10;
int c = 99;
int [] s = {0, 22, 84, 97, 47, 20, 64, 43, 11, 56, 96}; //s[0] is not used
WorstFit.worstFitPack(s, c);
}
}