Browse Source

restructured code, finalizing

master
David 2 years ago
parent
commit
d8c6c0e53b
1 changed files with 25 additions and 23 deletions
  1. +25
    -23
      src/ChainQueue.java

+ 25
- 23
src/ChainQueue.java View File

@@ -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;
}
}

Loading…
Cancel
Save