Implementato parzialmente l'arraysequence

This commit is contained in:
2014-03-30 17:43:15 +02:00
parent c25afb02a2
commit 5cc6be1a96
4 changed files with 214 additions and 3 deletions

View File

@@ -0,0 +1,55 @@
package sequence.utility;
import exceptions.InvalidPositionException;
import position.Position;
/**
* A simple node class for a doubly-linked list. Each DNode has a
* reference to a stored element, a previous node, and a next node.
*
* @author Roberto Tamassia
*/
//Copyright (c) 2003 Brown University, Providence, RI
//Additional modifications and methods by xgiovio
public class DNodeIndex<E> implements Position<E> {
private DNodeIndex<E> prev = null;
private DNodeIndex<E> next = null;
private E element = null;
private int index = -1;
public DNodeIndex(DNodeIndex<E> newPrev, DNodeIndex<E> newNext, E elem, int in_idex) {
prev = newPrev;
next = newNext;
element = elem;
index = in_idex;
}
public DNodeIndex(DNodeIndex<E> newPrev, DNodeIndex<E> newNext, E elem) {
prev = newPrev;
next = newNext;
element = elem;
}
public E element() throws InvalidPositionException {
if ((prev == null) && (next == null))
throw new InvalidPositionException("Position is not in a list!");
return element;
}
public DNodeIndex<E> getNext() { return next; }
public DNodeIndex<E> getPrev() { return prev; }
public void setNext(DNodeIndex<E> newNext) { next = newNext; }
public void setPrev(DNodeIndex<E> newPrev) { prev = newPrev; }
public void setElement(E newElement) { element = newElement; }
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
}