-1

I am trying to implement a linked list in java. From my knowledge of C++ linked list were implemented by creating a node class:::

struct Node
{
int data;
struct Node *next;
}

And similiar to this I've found that in java node is created by:::

class Node {
int data;
Node next;
}

My doubt is that in the java class there is no address pointing to the next node. In fact what I am able to interpret is that every node recursively will have another node inside it and not its location which theoretically should be the case. I tried finding some help on java forums and they say that the "next" node is actually acting like the c++ pointer but syntax-wise I don't see why would it give the address and not the node itself.

Codor
  • 17,447
  • 9
  • 29
  • 56
P_K
  • 11
  • 4

1 Answers1

0

"In fact what I am able to interpret is that every node recursively will have another node inside it and not its location " is not true, the node attribute in a node instance will be set to a reference to the next node, not the object itself

  • I could be wrong on this but why must it be so? If we are creating an object or variable then it is supposed to store data inside it and not its location on the memory. – P_K Jul 12 '16 at 14:56