public class LinkedList<E>
extends java.lang.Object
implements java.lang.Iterable<E>
Modifier and Type | Class and Description |
---|---|
private class |
LinkedList.LinkedListIterator<E>
Iterator class for better loop iteration
|
private class |
LinkedList.Node<T>
Node data structure which the linked list refers to
|
Modifier and Type | Field and Description |
---|---|
private LinkedList.Node<E> |
head |
private int |
length |
private LinkedList.Node<E> |
tail |
Constructor and Description |
---|
LinkedList() |
LinkedList(E o) |
Modifier and Type | Method and Description |
---|---|
void |
append(E o)
Append a node containing a creature to the linked list
|
LinkedList<E> |
copy()
Make a copy of the data structure
|
boolean |
exists(E o)
Checks to see if the object o is inside the list
|
int |
getIndexOfObject(E o)
Gets the object at given index
|
private LinkedList.Node<E> |
getNodeAtIndex(int index)
Gets the node at given index
|
E |
getObjectAtIndex(int index)
Gets the object at given index
|
void |
insertAt(int index,
E o)
Insert an object o into the linked list at position index.
|
boolean |
isEmpty() |
java.util.Iterator<E> |
iterator()
Allow the linked list to be iterable
|
int |
length()
The total number of nodes in the list
|
void |
prepend(E o)
Prepend a node containing a creature to the linked list
|
boolean |
remove(E object) |
boolean |
removeAt(int index) |
LinkedList<E> |
shallowCopy()
Make a shallow copy of the data structure, only copying the reference
to each
|
void |
swap(int a,
int b)
Not enough time to implement this method
|
private LinkedList.Node<E> head
private LinkedList.Node<E> tail
private int length
LinkedList()
LinkedList(E o)
public void prepend(E o)
n
- A Creature referencepublic void append(E o)
n
- A Creature referencepublic boolean isEmpty()
public int length()
public void insertAt(int index, E o) throws LinkedListException
the
- location which will take the place of the new objectthe
- object to insertLinkedListException
public boolean remove(E object)
public boolean removeAt(int index)
public boolean exists(E o)
o
- object to search forprivate LinkedList.Node<E> getNodeAtIndex(int index)
index
- the position in the list to look forpublic E getObjectAtIndex(int index)
index
- the position in the list to look forpublic int getIndexOfObject(E o)
index
- the position in the list to look forpublic LinkedList<E> copy()
public LinkedList<E> shallowCopy()
public void swap(int a, int b)
Harry Scells 2015 CSC241