fixes
This commit is contained in:
@@ -63,6 +63,11 @@ public class NodePositionListTest {
|
|||||||
System.out.print(it.next());
|
System.out.print(it.next());
|
||||||
System.out.print(it.hasNext());
|
System.out.print(it.hasNext());
|
||||||
|
|
||||||
|
System.out.print(a.positions().iterator());
|
||||||
|
System.out.print(it.hasNext());
|
||||||
|
System.out.print(((Position<Integer>)(it.next().);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -198,73 +198,91 @@ public class NodePositionList<E> implements PositionList<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// inception style. a dream in a dream in a dream
|
||||||
|
|
||||||
public Iterator<Position<E>> positions() {
|
public Iterable<Position<E>> positions() {
|
||||||
return new MyPositionsIterator(this);
|
return new MyPositionsIterable(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyPositionsIterator implements Iterator<Position<E>>{
|
class MyPositionsIterable implements Iterable<Position<E>>{
|
||||||
|
|
||||||
public MyPositionsIterator (NodePositionList<E> structure){
|
private NodePositionList<E> base = null;
|
||||||
|
|
||||||
new_structure = new NodePositionList<Position<E>>();
|
public MyPositionsIterable(NodePositionList<E> in){
|
||||||
if (structure.size() != 0){
|
base = in;
|
||||||
Position<E> temp;
|
}
|
||||||
for (temp = structure.first() ; temp!= structure.last() ; temp = structure.next(temp)){
|
|
||||||
|
@Override
|
||||||
|
public Iterator<Position<E>> iterator() {
|
||||||
|
return new MyPositionsIterator(base);
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyPositionsIterator <E> implements Iterator<Position<E>> {
|
||||||
|
public MyPositionsIterator (NodePositionList<E> structure){
|
||||||
|
|
||||||
|
new_structure = new NodePositionList<Position<E>>();
|
||||||
|
if (structure.size() != 0){
|
||||||
|
Position<E> temp;
|
||||||
|
for (temp = structure.first() ; temp!= structure.last() ; temp = structure.next(temp)){
|
||||||
|
new_structure.addLast(temp);
|
||||||
|
}
|
||||||
new_structure.addLast(temp);
|
new_structure.addLast(temp);
|
||||||
}
|
}
|
||||||
new_structure.addLast(temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNext() {
|
|
||||||
if (pos == null){
|
|
||||||
if (new_structure.size() <= 0){
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
try {
|
|
||||||
new_structure.next(pos);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (BoundaryViolationException err){
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Position<E> next() throws NoSuchElementException {
|
public boolean hasNext() {
|
||||||
if (hasNext()){
|
|
||||||
if (pos == null){
|
if (pos == null){
|
||||||
pos = new_structure.first();
|
if (new_structure.size() <= 0){
|
||||||
}else {
|
return false;
|
||||||
pos = new_structure.next(pos);
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
try {
|
||||||
|
new_structure.next(pos);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (BoundaryViolationException err){
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return pos.element();
|
|
||||||
} else{
|
|
||||||
throw new NoSuchElementException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Position<E> next() throws NoSuchElementException {
|
||||||
|
if (hasNext()){
|
||||||
|
if (pos == null){
|
||||||
|
pos = new_structure.first();
|
||||||
|
}else {
|
||||||
|
pos = new_structure.next(pos);
|
||||||
|
}
|
||||||
|
return pos.element();
|
||||||
|
} else{
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove() {
|
||||||
|
throw new UnsupportedOperationException ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
NodePositionList<Position<E>> new_structure;
|
||||||
|
Position<Position<E>> pos = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove() {
|
|
||||||
throw new UnsupportedOperationException ();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
NodePositionList<Position<E>> new_structure;
|
|
||||||
Position<Position<E>> pos = null;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// end inception style
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class SortedListPriorityQueue<K,V> implements PriorityQueue<K,V> {
|
|||||||
data.addFirst(t);
|
data.addFirst(t);
|
||||||
return t;
|
return t;
|
||||||
} else {
|
} else {
|
||||||
Iterator<Position<MyEntry<K, V>>> itp = data.positions();
|
Iterator<Position<MyEntry<K, V>>> itp = data.positions().iterator();
|
||||||
int status;
|
int status;
|
||||||
Position<MyEntry<K, V>> temp_pos = null;
|
Position<MyEntry<K, V>> temp_pos = null;
|
||||||
for (; itp.hasNext(); ) {
|
for (; itp.hasNext(); ) {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class UnsortedListPriorityQueue<K,V> implements PriorityQueue<K,V> {
|
|||||||
if (isEmpty()){
|
if (isEmpty()){
|
||||||
throw new EmptyPriorityQueueException();
|
throw new EmptyPriorityQueueException();
|
||||||
} else {
|
} else {
|
||||||
Iterator<Position<MyEntry<K, V>>> itp = data.positions();
|
Iterator<Position<MyEntry<K, V>>> itp = data.positions().iterator();
|
||||||
int status;
|
int status;
|
||||||
Position<MyEntry<K, V>> min = null;
|
Position<MyEntry<K, V>> min = null;
|
||||||
Position<MyEntry<K, V>> temp_pos = null;
|
Position<MyEntry<K, V>> temp_pos = null;
|
||||||
@@ -83,7 +83,7 @@ public class UnsortedListPriorityQueue<K,V> implements PriorityQueue<K,V> {
|
|||||||
if (isEmpty()){
|
if (isEmpty()){
|
||||||
throw new EmptyPriorityQueueException();
|
throw new EmptyPriorityQueueException();
|
||||||
} else {
|
} else {
|
||||||
Iterator<Position<MyEntry<K, V>>> itp = data.positions();
|
Iterator<Position<MyEntry<K, V>>> itp = data.positions().iterator();
|
||||||
int status;
|
int status;
|
||||||
Position<MyEntry<K, V>> min = null;
|
Position<MyEntry<K, V>> min = null;
|
||||||
Position<MyEntry<K, V>> temp_pos = null;
|
Position<MyEntry<K, V>> temp_pos = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user