I am new in Java. I am used to use C++.
I have problems with implementing tree without pointers. Is there any
standard collection like ArrayList to do that?
I have a problem when i want to get a successors of any node. When nodeA =
nodeB.succ() there is a copy of nodeB in nodeA... not a reference :(. So
when i next do nodeA.succ() it is not working...

Signature
Best regards,
Odwrotnie.
zero - 11 Feb 2006 19:21 GMT
> I am new in Java. I am used to use C++.
>
[quoted text clipped - 4 lines]
> nodeA = nodeB.succ() there is a copy of nodeB in nodeA... not a
> reference :(. So when i next do nodeA.succ() it is not working...
It is a common misconception that Java does not have pointers. Java has
references, which are very much alike C++ pointers. The biggest
differences are that there is no pointer arithmatic, and references always
point to a valid object of the same type (or null). For a more
comprehensive list of differences, see
http://mindprod.com/jgloss/pointer.html and
http://mindprod.com/jgloss/reference.html
So what does this mean for tree structures? Basically, you can use your
C++ code by deleting the *s and changing the -> to . (dot)
Yes of course it's a little more complicated than that, but not really that
much.
For an example of a binary tree in both C++ and Java, have a look at:
http://cslibrary.stanford.edu/110/BinaryTrees.html#java
Roedy Green - 12 Feb 2006 04:59 GMT
>I have problems with implementing tree without pointers. Is there any
>standard collection like ArrayList to do that?
What were you thinking of using to track the connections? a matrix,
array indexes? What's the matter with references? That is how it is
always done.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.