# Do nodes contain 3 pieces of data in this LinkedList?

My algorithms & data structures textbook has an implementation of LinkedList. I'm looking at lines 8 through 16 the java code below. So, the node is comprised of three parts: the data (in the form of an object), the previous node, and the next node, is that correct?
``````public class MyLinkedList<AnyType> implements Iterable<AnyType> {

private int theSize;
private int modCount = 0;
private Node<AnyType> beginMarker;
private Node<AnyType> endMarker;

private static class Node<AnyType>
{
public Node( AnyType d, Node<AnyType> p, Node<AnyType> n ) {
data = d; prev = p; next = n;}

public AnyType data;
public Node<AnyType> = prev;
public Node<AnyType> = next;
}

clear( );}

public void clear( ) // Change the size of this collection to zero.
{
beginMarker = new Node<AnyType>( null, null, null );
endMarker = new Node<AnyType>( null, beginMarker, null );
beginMarker.next = endMarker;

theSize = 0;
modCount++;
}

public int size( ) { //Returns the number of items in this collection.
return theSize;
}

public boolean isEmpty( ) {
return size( ) == 0;}

public boolean add( AnyType x ) { //Adds an item to this collection, at the end
return true;
}

/* the add method adds an item to this collection, at specified position. * Items at or after that 	position are slid one position higher */

public void add( int idx, AnyType x ) {

public AnyType get( int idx ) { // Returns the item at position idx
return getNode( idx ).data;}

public AnyType set( int idx, AnyType newVal ) { //Changes the item at position idx
Node<AnyType> p = getNode( idx );
AnyType oldVal = p.data;
p.data = newVal;
return oldVal;
}

public AnyType remove( int idx ) { //Removes an item from this collection
return	remove(getNode( idx ));}

/* this addBefore method adds an item to this collection, at specified position p.
Items at or after that position are slid one position higher */

private void addBefore( Node<AnyType> p, AnyType x ) {
Node<AnyType> newNode = new Node<AnyType>( x, p.prev, p );
newNode.prev.next = newNode;
p.prev = newNode;
theSize++;
modCount++;
}

private AnyType remove( Node<AnyType> p ) {  // Removes the object contained in Node p.
p.next.prev = p.prev;
p.prev.next = p.next;
theSize--;
modCount++
return p.data;
}

private Node<AnyType> getNode( int idx)
{
Node<AnyType> p;

if( idx < 0 || idx > size() )
throw new IndexOutOfBoundsException();

if( idx < size( ) / 2 ) {
p = beginMarker.next;
for( int i = 0; i < idx; i++ )
p = p.next;
}
else
{
p = endMarker;
for( int i = size( ); i > idx; i-- )
p = p.prev;
}

return p;
}

public java.util.Iterator<AnyType> iterator( ) {
}

{
private Node<AnyType> current = beginMarker.next;
private int expectedModCount = modCount;
private boolean okToRemove = false;

public boolean hasNext( ) {
return current != endMarker;
}

public AnyType next( )
{
if( modCount != expectedModCount )
throw new java.util.ConcurrentModificationException( );
if( !hasNext( ) )
throw new java.util.NoSuchElementException( );

AnyType nextItem = current.data;
current = current.next;
okToRemove = true;
return nextItem;
}

public void remove( )
{
if( modCount != expectedModCount )
throw new java.util.ConcurrentModificationException( );
if( !okToRemove )
throw new IllegalStateException( );

okToRemove = false;
expectedModCount++;
}
}
}
``````
###### Who is Participating?

Commented:
I mean that the minimal structure includes:
the data
a pointer to the next element
a pointer to the previous element.

In general formal definition of a linked list, there is no pointer to the previous element, but it helps a lot in browsing element.
When you have a pointer to the previous element, it is named double linked list.
See here for reference:
0

Commented:
Yes, you are true.
This is a tipical structure of a linked list
0

Author Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.