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;

}

[316 byte] By [patitasa] at [2007-11-27 11:37:15]
# 1

> 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?

~

yawmarka at 2007-7-29 17:13:28 > top of Java-index,Java Essentials,New To Java...
# 2

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

}

patitasa at 2007-7-29 17:13:28 > top of Java-index,Java Essentials,New To Java...
# 3

> yes

Then why are you trying to assign an int value to an element of a Node[] array?*

* heapArray[key++] = n % 2;

~

yawmarka at 2007-7-29 17:13:28 > top of Java-index,Java Essentials,New To Java...
# 4

so why then are you trying to make a node variable hold an int? It doesn't make sense.

petes1234a at 2007-7-29 17:13:28 > top of Java-index,Java Essentials,New To Java...
# 5

are you looking to call setNodeValue?

petes1234a at 2007-7-29 17:13:28 > top of Java-index,Java Essentials,New To Java...
# 6

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()

patitasa at 2007-7-29 17:13:28 > top of Java-index,Java Essentials,New To Java...
# 7

>> 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.

TuringPesta at 2007-7-29 17:13:28 > top of Java-index,Java Essentials,New To Java...