public class LinkedList
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected Node |
head
The first
Node in the LinkedList. |
protected Node |
tail
The last
Node in the LinkedList. |
| Constructor and Description |
|---|
LinkedList()
Empty constructor.
|
LinkedList(Node node)
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
append(int data)
Add a value to the
LinkedList. |
void |
append(Node node)
Add a
Node to the LinkedList. |
boolean |
contains(int data)
Tests if a value is contained in the
LinkedList. |
boolean |
contains(Node node)
Tests if a
Node is contained in the LinkedList. |
Node |
getHead()
Get the head of the
LinkedList. |
Node |
getTail()
Get the tail of the
LinkedList. |
boolean |
isEmpty()
Test if the
LinkedList is empty. |
void |
remove()
Removes a
Node from the end of the LinkedList. |
void |
setHead(Node node)
Set the head of the
LinkedList. |
void |
setTail(Node node)
Set the tail of the
LinkedList. |
java.lang.String |
toString()
Create a
String representation of the
LinkedList. |
protected Node head
Node in the LinkedList.protected Node tail
Node in the LinkedList.public LinkedList()
LinkedList.public LinkedList(Node node)
LinkedList with the given Node as the
head.node - the first Node in the LinkedListpublic void setHead(Node node)
LinkedList.node - the new headpublic void setTail(Node node)
LinkedList.node - the new tailpublic Node getHead()
LinkedList.public Node getTail()
LinkedList.public boolean isEmpty()
LinkedList is empty.true if the LinkedList is empty,
false otherwisepublic void append(Node node)
Node to the LinkedList.node - the Node to addpublic void append(int data)
LinkedList.data - the value to addpublic void remove()
Node from the end of the LinkedList.public boolean contains(int data)
LinkedList.data - the value to findtrue if the value is found, false
otherwisepublic boolean contains(Node node)
Node is contained in the LinkedList.
This checks for the data within the Node, not the reference
itself.node - the Node to findtrue if the Node is found,
false otherwisepublic java.lang.String toString()
String representation of the
LinkedList.toString in class java.lang.ObjectLinkedList as a String