• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can anybody help me in understanding this piece of code

 
Greenhorn
Posts: 18
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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



 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 18
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Drove my Chevy to the levee but the levee was dry. A wrung this tiny ad and it was still dry.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic