T - the entry typepublic class LinkedList<T>
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
LinkedList.Entry<T>
Defines a list entry.
|
| Modifier and Type | Field and Description |
|---|---|
private LinkedList.Entry<T> |
header
Defines the dummy header element where to hook into further list
elements.
|
private int |
size
Stores the size of the list.
|
| Constructor and Description |
|---|
LinkedList()
Constructs an empty list.
|
| Modifier and Type | Method and Description |
|---|---|
private LinkedList.Entry<T> |
addBefore(T value,
LinkedList.Entry<T> entry)
Adds a new entry before
entry. |
void |
addFirst(T value)
Inserts the specified element at the beginning of this list.
|
void |
addLast(T value)
Appends the specified element to the end of this list.
|
void |
appendAllTo(LinkedList<T> list)
Appends all elements in this list to the end of
list. |
void |
clear()
Removes all of the elements from this list.
|
boolean |
isEmpty()
Returns whether the list is empty.
|
private T |
remove(LinkedList.Entry<T> entry)
Removes the given entry.
|
T |
removeFirst()
Removes and returns the first element from this list.
|
T |
removeLast()
Removes and returns the last element from this list.
|
int |
size()
Returns the number of elements in this list.
|
java.lang.String |
toString()
Returns a textual representation of this object.
|
private LinkedList.Entry<T> header
private int size
private T remove(LinkedList.Entry<T> entry)
entry - the entry to be removedjava.util.NoSuchElementException - if the entry cannot be removedpublic T removeFirst()
java.util.NoSuchElementException - if this list is emptypublic T removeLast()
java.util.NoSuchElementException - if this list is emptypublic void addFirst(T value)
value - the element to addpublic void addLast(T value)
value - the element to addpublic void appendAllTo(LinkedList<T> list)
list.list - the target listpublic java.lang.String toString()
toString in class java.lang.Objectprivate LinkedList.Entry<T> addBefore(T value, LinkedList.Entry<T> entry)
entry.value - the entry valueentry - the entry to insert into beforepublic void clear()
public int size()
public boolean isEmpty()
true if it is empty, false else