Class DLinkedList<X>
java.lang.Object
Jcg.util.DLinkedList<X>
Minimal implementation of a doubly connected linked list, storing generic type elements.
It uses sentinel (dummy and empty) nodes to represent the beginning and the end of the list.
It uses sentinel (dummy and empty) nodes to represent the beginning and the end of the list.
- Author:
- Luca Castelli Aleardi (Ecole Polytechnique, 2013)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAppend a new element at the beginning of the listvoidInsert a new element at the beginning of the listvoidAppend a new element at the end of the listvoidappend(DLinkedList<X> l2) Append the cells of 'l2' to the current list.copy()Return a new linkedList, copy of the current list: only the content is copied (nodes are different)voidRemove a given node from the listbooleanequal(DLinkedList<X> list) Check equality between two lists: only the contents do countgetEnd()Return the end of the list: useful for iterating over the nodesgetFirst()Return the first node of the list The result is a null reference if the list is emptygetLast()Return the last node of the list The result is a null reference if the list is emptygetStart()Return the 'start' of the list: useful for creating circular listsvoidinsertAfter(DListNode<X> pNode, X el) Insert a new element after a given node in the listvoidinsertBefore(DListNode<X> pNode, X el) Insert a new element before a given node in the listbooleanisEmpty()Check whether the list is emptyintsize()toString()Return a String representing the list
-
Field Details
-
first
-
last
-
size
private int size
-
-
Constructor Details
-
DLinkedList
public DLinkedList()
-
-
Method Details
-
copy
Return a new linkedList, copy of the current list: only the content is copied (nodes are different) -
equal
Check equality between two lists: only the contents do count -
size
public int size() -
isEmpty
public boolean isEmpty()Check whether the list is empty -
getStart
-
getEnd
-
getFirst
-
getLast
-
addFirst
Insert a new element at the beginning of the list- Parameters:
el- the element to insert
-
addLast
Append a new element at the end of the list- Parameters:
el- the element to insert
-
add
Append a new element at the beginning of the list- Parameters:
el- the element to insert
-
append
Append the cells of 'l2' to the current list. The merge is performed only when both lists are not empty.
Remark: this operation takes only constant time.
Warnings: -) both lists are modified- Parameters:
l2- the list to be added (at the end of the current list)
-
insertAfter
-
insertBefore
-
delete
-
toString
-