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 / General / July 2006

Tip: Looking for answers? Try searching our database.

references

Thread view: 
justplain.kzn@gmail.com - 24 Jul 2006 05:06 GMT
Hi,

I am new to java programming and seem to have got myself into a bit of
confusion with assigning and using reference variables.
Below is a snippet of code I an using for a linkedlist.

public class LinkedList
{
  private Node start;

  public LinkedList()
  {
     start=null;
  }

  public Node find (int x)
  {
     if (start==null || start.data>0)
        return null;
     Node p = start;                //*************** help
     while (p.next != nul && !(p.next.data > x))
        p=p.next;
     return p;
  }

...
...
}

Can some please point out and explain to me why when assigning
reference 'start' to p and then using p within the while loop, start is
NOT affected/changed?

thanks in advance...
jtl.zheng - 24 Jul 2006 05:20 GMT
guest first the 'start' point to a object called "Oa"
Node p = start; // make the "p" point to what the start point to, it's
"Oa"
p=p.next; // at this time the p point to another object
but the 'start' still point to "Oa"
no one change it
justplain.kzn@gmail.com - 24 Jul 2006 05:26 GMT
Ah - thanks a million. I now see that p and start point to the same
just once. p.next is actually a NEW OBJECT reference...

thanks again...

> guest first the 'start' point to a object called "Oa"
> Node p = start; // make the "p" point to what the start point to, it's
> "Oa"
> p=p.next; // at this time the p point to another object
> but the 'start' still point to "Oa"
> no one change it
jtl.zheng - 24 Jul 2006 05:31 GMT
yes..that's right
: )


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.