Question about linked lists in Java
Cat--开发者_如何学JAVA---->Dog------>Horse----->Parrot
^P1 ^P2 ^P3 ^P4
Draw the resulting linked list after executing the following statements:
P4 = P2;
P3.info = P2.info
etc.
My question is, what does '.info' reference?
I've looked in the API for both node and linked list and haven't found anything. Any ideas?This would entirely depend on the specific implementation used in your assignment, but it sounds like info
contains the data of the specific node in the linked list, i.e. P1.info
is Cat
.
Each node in a standard linked list has two pieces of information:
- A reference the the next node
- The data contained in the current node
I'm not sure if your instructor wants you to take into account that you would have to "clone" the node in order to have a separate object with the same data or if your instructor wants you to take it literally where setting one object equal to another object simply makes the first one a reference to the second one.
As spookyjon said, the info appears to be a public variable in the node class for the data (cat, dog, horse, parrot).
精彩评论