public class Node<E>
extends java.lang.Object
BooleanNode,
ByteNode,
CharNode,
DoubleNode,
FloatNode,
IntNode,
LongNode,
ShortNode| Constructor and Description |
|---|
Node(E initialData,
Node<E> initialLink)
Initialize a node with a specified initial data and link to the next
node.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addNodeAfter(E element)
Modification method to add a new node after this node.
|
E |
getData()
Accessor method to get the data from this node.
|
Node<E> |
getLink()
Accessor method to get a reference to the next node after this node.
|
static <E> Node<E> |
listCopy(Node<E> source)
Copy a list.
|
static <E> java.lang.Object[] |
listCopyWithTail(Node<E> source)
Copy a list, returning both a head and tail reference for the copy.
|
static <E> int |
listLength(Node<E> head)
Compute the number of nodes in a linked list.
|
static <E> java.lang.Object[] |
listPart(Node<E> start,
Node<E> end)
Copy part of a list, providing a head and tail reference for the new copy.
|
static <E> Node<E> |
listPosition(Node<E> head,
int position)
Find a node at a specified position in a linked list.
|
static <E> Node<E> |
listSearch(Node<E> head,
E target)
Search for a particular piece of data in a linked list.
|
void |
removeNodeAfter()
Modification method to remove the node after this node.
|
void |
setData(E newData)
Modification method to set the data in this node.
|
void |
setLink(Node<E> newLink)
Modification method to set the link to the next node after this node.
|
public Node(E initialData, Node<E> initialLink)
initialData - the initial data of this new nodeinitialLink - a reference to the node after this new node--this reference may be null
to indicate that there is no node after this new node.public void addNodeAfter(E element)
element - the data to place in the new nodejava.lang.OutOfMemoryError - Indicates that there is insufficient memory for a new
Node.public E getData()
public Node<E> getLink()
public static <E> Node<E> listCopy(Node<E> source)
E - type of an element in the listsource - the head of a linked list that will be copied (which may be
an empty list in where source is null)java.lang.OutOfMemoryError - Indicates that there is insufficient memory for the new list.public static <E> java.lang.Object[] listCopyWithTail(Node<E> source)
E - type of an element in the listsource - the head of a linked list that will be copied (which may be
an empty list in where source is null)java.lang.OutOfMemoryError - Indicates that there is insufficient memory for the new list.public static <E> int listLength(Node<E> head)
E - type of an element in the listhead - the head reference for a linked list (which may be an empty list
with a null head)public static <E> java.lang.Object[] listPart(Node<E> start, Node<E> end)
E - type of an element in the liststart - references to start node of a linked listend - references to end node of a linked listjava.lang.IllegalArgumentException - Indicates that start and end do not satisfy
the precondition.java.lang.OutOfMemoryError - Indicates that there is insufficient memory for the new list.public static <E> Node<E> listPosition(Node<E> head, int position)
E - type of an element in the listhead - the head reference for a linked list (which may be an empty list in
which case the head is null)position - a node numberjava.lang.IllegalArgumentException - Indicates that position is zero.public static <E> Node<E> listSearch(Node<E> head, E target)
E - type of an element in the listhead - the head reference for a linked list (which may be an empty list in
which case the head is null)target - a target to search forpublic void removeNodeAfter()
java.lang.NullPointerException - Indicates that this was the tail node of the list, so there is nothing
after it to remove.public void setData(E newData)
newData - the new data to place in this nodepublic void setLink(Node<E> newLink)
newLink - a reference to the node that should appear after this node in the linked
list (or the null reference if there is no node after this node)