|
|
@@ -94,6 +94,31 @@ public class ChainQueue<E> implements Queue<E> { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public E poll() { // poll next from queue and remove the first |
|
|
|
E temp = null; |
|
|
|
if (!this.isEmpty()) { |
|
|
|
temp = getFirst().getData(); |
|
|
|
setFirst(getFirst().getNext()); |
|
|
|
} |
|
|
|
return temp; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public E element() { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public E peek() { // only "see" into the queue and do not remove anything |
|
|
|
if (!this.isEmpty()) { |
|
|
|
return getFirst().getData(); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
/*** the following is not implemented because it's not needed here ***/ |
|
|
|
|
|
|
|
@Override |
|
|
|
public Iterator<E> iterator() { |
|
|
|
return null; |
|
|
@@ -148,27 +173,4 @@ public class ChainQueue<E> implements Queue<E> { |
|
|
|
public E remove() { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public E poll() { // poll next from queue and remove the first |
|
|
|
E temp = null; |
|
|
|
if (!this.isEmpty()) { |
|
|
|
temp = getFirst().getData(); |
|
|
|
setFirst(getFirst().getNext()); |
|
|
|
} |
|
|
|
return temp; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public E element() { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public E peek() { // only "see" into the queue and do not remove anything |
|
|
|
if (!this.isEmpty()) { |
|
|
|
return getFirst().getData(); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |