Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / February 2006

Tip: Looking for answers? Try searching our database.

Implementing trees without pointers?

Thread view: 
odwrotnie - 11 Feb 2006 18:19 GMT
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.