Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DesertFox

macrumors member
Original poster
Nov 25, 2004
72
0
Hello again,

Im getting an error on the 4th line (node leftChild) of this Node code snippet.

Error: cannot find symbol
symbol: class node
location: class node

Is there a different way to declare nodes? or is there a syntax error?

Thanks in advance!



class Node
{
int iData;
float fData;
node leftChild;
node rightChild;

public void displayNode()
{
// method body
}
}
 
I'm going to take a wild guess and say it should be Node, not node. You have to match whatever case you used for the name of your class.

class Node {
int iData;
float fData;
Node leftChild;
Node rightChild;

}
 
That seemed to fix that problem, but now Im getting a new one:

public Node minimum() // returns node with minimum key value
{
Node current;
Node last;
current = root; // start at root
while(current != null) // until the bottom,
{
last = current; // remember node
current = current.leftChild; // go to left child
}
return last;

}

Error: variable last might not have been initialized

But, we can clearly see that it is initialized at the top of the method.

Does anyone know whats going on here?

Thanks!
 
That seemed to fix that problem, but now Im getting a new one:

Error: variable last might not have been initialized

But, we can clearly see that it is initialized at the top of the method.
Actually, it's not being initialized. It's being declared. To initialize it, you need to explicitly assign a value to it (null is okay).

Try changing that line to:
Code:
Node last = null;
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.