Package org.apache.batik.util
Class DoublyLinkedList
java.lang.Object
org.apache.batik.util.DoublyLinkedList
A simple Doubly Linked list class, designed to avoid
O(n) behaviour on insert and delete.
- Version:
- $Id: DoublyLinkedList.java 1733416 2016-03-03 07:07:13Z gadams $
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Basic doubly linked list node interface. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int index, DoublyLinkedList.Node nde) void
add
(DoublyLinkedList.Node nde) Addsnde
to the head of the list.void
empty()
Removes all elements from the list.getHead()
Get the current head elementint
getSize()
Returns the number of elements currently in the list.getTail()
Get the current tail elementpop()
Removes 'head' from list and returns it.void
Addsnde
to tail of listvoid
Removes nde from the list it is part of (should be this one, otherwise results are undefined).void
Movesnde
to the head of the list (equivilent to remove(nde); add(nde); but faster.void
Addsnde
to head of listunpush()
Removes 'tail' from list and returns it.
-
Field Details
-
head
-
size
private int size
-
-
Constructor Details
-
DoublyLinkedList
public DoublyLinkedList()
-
-
Method Details
-
getSize
public int getSize()Returns the number of elements currently in the list. -
empty
public void empty()Removes all elements from the list. -
getHead
Get the current head element- Returns:
- The current 'first' element in list.
-
getTail
Get the current tail element- Returns:
- The current 'last' element in list.
-
touch
Movesnde
to the head of the list (equivilent to remove(nde); add(nde); but faster. -
add
-
add
Addsnde
to the head of the list. In perl this is called an 'unpop'.nde
should not currently be part of any list.- Parameters:
nde
- the node to add to the list.
-
remove
Removes nde from the list it is part of (should be this one, otherwise results are undefined). If nde is the current head element, then the next element becomes head, if there are no more elements the list becomes empty.- Parameters:
nde
- node to remove.
-
pop
Removes 'head' from list and returns it. Returns null if list is empty.- Returns:
- current head element, next element becomes head.
-
unpush
Removes 'tail' from list and returns it. Returns null if list is empty.- Returns:
- current tail element.
-
push
Addsnde
to tail of list -
unpop
Addsnde
to head of list
-