structure5
Class Node<E>

java.lang.Object
  extended by structure5.Node<E>

public class Node<E>
extends java.lang.Object

A class supporting a singly linked list element. Each element contains a value and maintains a single reference to the next node in the list.


Field Summary
protected  E data
          The data value stored in this node.
protected  Node<E> nextElement
          Reference to the next node in the list.
 
Constructor Summary
Node(E v)
          Constructs a node not associated with any list.
Node(E v, Node<E> next)
          Construct a singly linked list element.
 
Method Summary
 Node<E> next()
           
 void setNext(Node<E> next)
          Update the next element.
 void setValue(E value)
          Set the value associated with this element.
 java.lang.String toString()
          Construct a string representation of element.
 E value()
          Fetch the value associated with this element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

data

protected E data
The data value stored in this node.


nextElement

protected Node<E> nextElement
Reference to the next node in the list.

Constructor Detail

Node

public Node(E v,
            Node<E> next)
Construct a singly linked list element.

Parameters:
v - The value to be referenced by this element.
next - A reference to the next value in the list.
Precondition:
v is a value, next is a reference to remainder of list
Postcondition:
an element is constructed as the new head of list

Node

public Node(E v)
Constructs a node not associated with any list. next reference is set to null.

Parameters:
v - The value to be inserted into the node.
Postcondition:
constructs a new tail of a list with value v
Method Detail

next

public Node<E> next()
Postcondition:
returns reference to next value in list

setNext

public void setNext(Node<E> next)
Update the next element.

Parameters:
next - The new value of the next element reference.
Postcondition:
sets reference to new next value

value

public E value()
Fetch the value associated with this element.

Returns:
Reference to the value stored within this element.
Postcondition:
returns value associated with this element

setValue

public void setValue(E value)
Set the value associated with this element.

Parameters:
value - The new value to be associated with this element.
Postcondition:
sets value associated with this element

toString

public java.lang.String toString()
Construct a string representation of element.

Overrides:
toString in class java.lang.Object
Returns:
The string representing element.
Postcondition:
returns string representation of element