Package com.zybooks.dsaj.fundamental
Class DoublyLinkedList<E>
java.lang.Object
com.zybooks.dsaj.fundamental.DoublyLinkedList<E>
- Type Parameters:
E
- the element type
A basic doubly linked list implementation.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an element to the front of the list.void
Adds an element to the end of the list.first()
Returns (but does not remove) the first element of the list.boolean
isEmpty()
Tests whether the linked list is empty.last()
Returns (but does not remove) the last element of the list.Removes and returns the first element of the list.Removes and returns the last element of the list.int
size()
Returns the number of elements in the linked list.toString()
Produces a string representation of the contents of the list.
-
Constructor Details
-
DoublyLinkedList
public DoublyLinkedList()Constructs a new empty list.
-
-
Method Details
-
size
public int size()Returns the number of elements in the linked list.- Returns:
- number of elements in the linked list
-
isEmpty
public boolean isEmpty()Tests whether the linked list is empty.- Returns:
- true if the linked list is empty, false otherwise
-
first
Returns (but does not remove) the first element of the list.- Returns:
- element at the front of the list (or null if empty)
-
last
Returns (but does not remove) the last element of the list.- Returns:
- element at the end of the list (or null if empty)
-
addFirst
Adds an element to the front of the list.- Parameters:
e
- the new element to add
-
addLast
Adds an element to the end of the list.- Parameters:
e
- the new element to add
-
removeFirst
Removes and returns the first element of the list.- Returns:
- the removed element (or null if empty)
-
removeLast
Removes and returns the last element of the list.- Returns:
- the removed element (or null if empty)
-
toString
Produces a string representation of the contents of the list. This exists for debugging purposes only.
-