Incompatible Type Error
How do I make these statements compatible?
I'm getting an error of
incompatible types
found:int
required:Node
while (n >= 1)
{
heapArray[key++] = n % 2;
n = n / 2;
}
How do I make these statements compatible?
I'm getting an error of
incompatible types
found:int
required:Node
while (n >= 1)
{
heapArray[key++] = n % 2;
n = n / 2;
}
> How do I make these statements compatible?
> I'm getting an error of
> incompatible types
> found:int
> required:Node
"heapArray" wouldn't happen to be a Node[] array, would it?
~
yes
class Heap
{
private Node[] heapArray;
private int maxSize;
private int currentSize;
private int index;
// -
public Heap(int mx)// constructor
{
maxSize = mx;
currentSize = 0;
heapArray = new Node[maxSize]; // create array
}
> yes
Then why are you trying to assign an int value to an element of a Node[] array?*
* heapArray[key++] = n % 2;
~
I'm trying to change get the binary of the node number by repeatedly using the % operator to find the reminder (0 or 1).
I'm very new to this so don't know what I'm suppose to do to make this work.
public boolean insert(int key)
{
if(currentSize==maxSize)
return false;
currentSize++;
Node newNode = new Node(key);
heapArray[currentSize] = newNode;
int n = currentSize;
while (n >= 1)
{
heapArray[key++] = n % 2;
n = n / 2;
}
trickleUp(currentSize++);
return true;
} // end insert()
>> I'm trying to change get the binary of the node number
huh? are you trying to get the digital root or the final bit?
n%2 will only tell you if its even or odd.