• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can anybody help me in understanding this piece of code  RSS feed

 
Debdeep Ganguly
Greenhorn
Posts: 16
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a beginner, so feel free to point out any mistakes or misconceptions.
I have a generic class Node, which i implemented in an other class - LinkedList. My question is - what does the line marked in the Node class part represent exactly. Thanks in advance.


Node class - Node.java




LinkedList class - LinkedList.java



 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37256
519
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That says your Node class has a reference to another Node class. That is what lets you represent the arrows in your Linked List.
 
Debdeep Ganguly
Greenhorn
Posts: 16
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes sure, an object is created, referenced to null but in the LinkedList class, it is given so what actually happens here ? Does the object takes all its values of next node and store it ? Where does the previous node's data go into, is it overwritten - mean how is memory allocation taking place ? Sorry if I am not able to clearly present my actual query here.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37256
519
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Debdeep,
That line doesn't change the objects in memory. Try this - get a piece of paper.

Draw one box and write node 1 in it. Then draw another box and write node 2 in it. At this point, you have two objects in memory that don't know about each other. Then draw an arrow from node1 to node2. That arrow is this line of code. It's updating the reference in memory. No new objects get created nor is anything transferred.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!