org.ddogleg.struct
Class LinkedList<T>
- java.lang.Object
-
- org.ddogleg.struct.LinkedList<T>
-
public class LinkedList<T> extends java.lang.ObjectA double linked list. Internal data structures are recycled to minimize creation of new memory.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classLinkedList.Element
-
Constructor Summary
Constructors Constructor and Description LinkedList()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddAll(java.util.List<T> list)Add all elements in list into this linked listvoidaddAll(T[] array, int first, int length)Adds the specified elements from array into this listLinkedList.Elementfind(T object)Returns the first element which contains 'object' starting from the head.LinkedList.ElementgetElement(int index, boolean fromFront)Returns the N'th element when counting from the from or from the backLinkedList.ElementgetHead()Returns the first element in the listLinkedList.ElementgetTail()Returns the last element in the listLinkedList.ElementinsertAfter(LinkedList.Element previous, T object)Inserts the object into a new element after the provided element.LinkedList.ElementinsertBefore(LinkedList.Element next, T object)Inserts the object into a new element before the provided element.booleanisEmpty()Checks to see if there are no elements in the listLinkedList.ElementpushHead(T object)Adds the element to the front of the list.LinkedList.ElementpushTail(T object)Adds the element to the back of the list.voidremove(LinkedList.Element element)Removes the element from the list and saves the element data structure for later reuse.java.lang.ObjectremoveHead()Removes the first element from the listjava.lang.ObjectremoveTail()Removes the last element from the listvoidreset()Puts the linked list back into its initial state.intsize()Returns the number of elements in the listvoidswap(LinkedList.Element a, LinkedList.Element b)Swaps the location of the two elements
-
-
-
Method Detail
-
reset
public void reset()
Puts the linked list back into its initial state. Elements are saved for later use.
-
isEmpty
public boolean isEmpty()
Checks to see if there are no elements in the list- Returns:
- true if empty or false if not
-
getElement
public LinkedList.Element getElement(int index, boolean fromFront)
Returns the N'th element when counting from the from or from the back- Parameters:
index- Number of elements away from the first or last element. Must be positive.- Returns:
- if true then the number of elements will be from first otherwise last
-
pushHead
public LinkedList.Element pushHead(T object)
Adds the element to the front of the list.- Parameters:
object- Object being added.- Returns:
- The element it was placed inside of
-
pushTail
public LinkedList.Element pushTail(T object)
Adds the element to the back of the list.- Parameters:
object- Object being added.- Returns:
- The element it was placed inside of
-
insertAfter
public LinkedList.Element insertAfter(LinkedList.Element previous, T object)
Inserts the object into a new element after the provided element.- Parameters:
previous- Element which will be before the new oneobject- The object which goes into the new element- Returns:
- The new element
-
insertBefore
public LinkedList.Element insertBefore(LinkedList.Element next, T object)
Inserts the object into a new element before the provided element.- Parameters:
next- Element which will be after the new oneobject- The object which goes into the new element- Returns:
- The new element
-
swap
public void swap(LinkedList.Element a, LinkedList.Element b)
Swaps the location of the two elements- Parameters:
a- Elementb- Element
-
remove
public void remove(LinkedList.Element element)
Removes the element from the list and saves the element data structure for later reuse.- Parameters:
element- The item which is to be removed from the list
-
removeHead
public java.lang.Object removeHead()
Removes the first element from the list- Returns:
- The object which was contained in the first element
-
removeTail
public java.lang.Object removeTail()
Removes the last element from the list- Returns:
- The object which was contained in the lsat element
-
find
public LinkedList.Element find(T object)
Returns the first element which contains 'object' starting from the head.- Parameters:
object- Object which is being searched for- Returns:
- First element which contains object or null if none can be found
-
getHead
public LinkedList.Element getHead()
Returns the first element in the list- Returns:
- first element
-
getTail
public LinkedList.Element getTail()
Returns the last element in the list- Returns:
- last element
-
addAll
public void addAll(java.util.List<T> list)
Add all elements in list into this linked list- Parameters:
list- List
-
addAll
public void addAll(T[] array, int first, int length)
Adds the specified elements from array into this list- Parameters:
array- The arrayfirst- First element to be addedlength- The number of elements to be added
-
size
public int size()
Returns the number of elements in the list
-
-
DataMelt 3.0 © DataMelt by jWork.ORG