com.intel.langutil
Class LinkedList<E>
- java.lang.Object
-
- com.intel.langutil.LinkedList<E>
-
public abstract class LinkedList<E> extends java.lang.Object
This class provides an implementation of a generic singly linked list.
-
-
Method Summary
Methods Modifier and Type Method and Description abstract void
add(E element)
Adds an element to the end of the listabstract void
add(E[] elements)
Adds an array of elements to the end of the listabstract void
addFirst(E element)
Adds an element to the beginning of the listabstract void
addLast(E element)
Adds an element to the end of the listabstract void
clear()
Removes all elements from the listabstract boolean
contains(E element)
Returns true iff the list contains the elementstatic <I> LinkedList<I>
create()
Factory method for creating concrete generic linked listsabstract E
getFirst()
Returns the first element in the listabstract Iterator<E>
getIterator()
Returns an iterator for thisLinkedList
.abstract E
getLast()
Returns the last element in the listabstract boolean
isEmpty()
Returns whether the list is emptyabstract E
remove()
Returns and removes the first element in the listabstract int
remove(E element)
Removes all the occurrence of element from the listabstract E
removeFirst()
Returns and removes the first element in the listabstract E
removeLast()
Returns and removes the last element in the listabstract int
size()
Returns the number of elements in the listabstract void
toArray(E[] array)
Exports the list to array of elements.
-
-
-
Method Detail
-
create
public static final <I> LinkedList<I> create()
Factory method for creating concrete generic linked lists- Returns:
- a generic
LinkedList
instance
-
add
public abstract void add(E element)
Adds an element to the end of the list- Parameters:
element
- the element to add to the list
-
addLast
public abstract void addLast(E element)
Adds an element to the end of the list- Parameters:
element
- the element to add to the list
-
addFirst
public abstract void addFirst(E element)
Adds an element to the beginning of the list- Parameters:
element
- the element to add to the list
-
add
public abstract void add(E[] elements)
Adds an array of elements to the end of the list- Parameters:
elements
- an array of elements to add to the list
-
contains
public abstract boolean contains(E element)
Returns true iff the list contains the element- Parameters:
element
- the element to query
-
clear
public abstract void clear()
Removes all elements from the list
-
size
public abstract int size()
Returns the number of elements in the list- Returns:
- returns the number of elements in the list
-
isEmpty
public abstract boolean isEmpty()
Returns whether the list is empty- Returns:
- returns true iff the list is empty
-
getFirst
public abstract E getFirst() throws java.util.NoSuchElementException
Returns the first element in the list- Returns:
- returns the first element in the list
- Throws:
java.util.NoSuchElementException
- if the list is empty
-
getLast
public abstract E getLast() throws java.util.NoSuchElementException
Returns the last element in the list- Returns:
- returns the last element in the list
- Throws:
java.util.NoSuchElementException
- if the list is empty
-
remove
public abstract E remove() throws java.util.NoSuchElementException
Returns and removes the first element in the list- Returns:
- returns the first element in the list
- Throws:
java.util.NoSuchElementException
- if the list is empty
-
removeFirst
public abstract E removeFirst() throws java.util.NoSuchElementException
Returns and removes the first element in the list- Returns:
- returns the first element in the list
- Throws:
java.util.NoSuchElementException
- if the list is empty
-
removeLast
public abstract E removeLast() throws java.util.NoSuchElementException
Returns and removes the last element in the list- Returns:
- returns the first element in the list
- Throws:
java.util.NoSuchElementException
- if the list is empty
-
remove
public abstract int remove(E element)
Removes all the occurrence of element from the list- Parameters:
element
- the element to remove- Returns:
- returns the number of occurrences removed
-
toArray
public abstract void toArray(E[] array)
Exports the list to array of elements. The array must have at leastsize()
elements.- Parameters:
array
- the array for output with the elements from the list
-
-