|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.AbstractSequentialList<E>
java.util.LinkedList<E>
fi.joensuu.cs.tra.LinkedDeque<E>
public class LinkedDeque<E>
LinkedDeque extends java.util.LinkedList to highlight Deque behaviour. It allows accessing, adding and removing elements elements from both ends of the queue. A simple example where a deque is split and then shuffled back together:
LinkedDequeThis should convert a deque of for example 1 2 3 4 5 6 7 8 9 to 9 1 8 2 7 3 6 4 5.mainDeq = new LinkedDeque (); LinkedDeque helpDeq1 = new LinkedDeque (); LinkedDeque helpDeq2 = new LinkedDeque (); // Let's assume there's something in mainDeq
// Split the original deque into two while (!mainDeq.isEmpty()) { // Insert elements to the first helper deque from the top // of the original deque. helpDeq1.addFirst(mainDeq.removeFirst()); // Insert elements to the second helper deque from the bottom if (!mainDeq.isEmpty()) helpDeq2.addFirst(mainDeq.removeLast()); } // Now start filling the original deque by adding elements alternating // between the helper deques while (!helpDeq1.isEmpty()) { mainDeq.addFirst(helpDeq1.removeFirst()); if (!helpDeq2.isEmpty()) mainDeq.addFirst(helpDeq2.removeFirst()); }
LinkedList
,
Serialized FormField Summary |
---|
Fields inherited from class java.util.AbstractList |
---|
modCount |
Constructor Summary | |
---|---|
LinkedDeque()
Creates an empty list. |
|
LinkedDeque(Collection<? extends E> c)
Constructs a deque containing the elements of the specified collection, in the order they are returned by the collection's iterator. |
Method Summary | |
---|---|
void |
addFirst(E o)
Inserts the given element to the front of this deque. |
void |
addLast(E o)
Inserts the given element to the rear of this deque. |
void |
clear()
Removes all the elements from this deque. |
E |
getFirst()
Returns but does not remove the element at the front of this deque. |
E |
getLast()
Returns but does not remove the element at the rear of this deque. |
E |
removeFirst()
Removes and returns the element at the front of this deque. |
E |
removeLast()
Removes and returns the element at the rear of this deque. |
Methods inherited from class java.util.LinkedList |
---|
add, add, addAll, addAll, clone, contains, element, get, indexOf, lastIndexOf, listIterator, offer, peek, poll, remove, remove, remove, set, size, toArray, toArray |
Methods inherited from class java.util.AbstractSequentialList |
---|
iterator |
Methods inherited from class java.util.AbstractList |
---|
equals, hashCode, listIterator, removeRange, subList |
Methods inherited from class java.util.AbstractCollection |
---|
containsAll, isEmpty, removeAll, retainAll, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
---|
containsAll, equals, hashCode, isEmpty, iterator, listIterator, removeAll, retainAll, subList |
Constructor Detail |
---|
public LinkedDeque()
public LinkedDeque(Collection<? extends E> c)
c
- the collection whose elements are to be placed into this deque.
NullPointerException
- if the specified collection was null.Method Detail |
---|
public void addFirst(E o)
addFirst
in class LinkedList<E>
o
- the element to be inserted.public void addLast(E o)
addLast
in class LinkedList<E>
o
- the element to be inserted.public void clear()
clear
in interface Collection<E>
clear
in interface List<E>
clear
in class LinkedList<E>
public E getFirst()
getFirst
in class LinkedList<E>
public E getLast()
getLast
in class LinkedList<E>
public E removeFirst()
removeFirst
in class LinkedList<E>
public E removeLast()
removeLast
in class LinkedList<E>
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |