Переглянути джерело

restructured code, finalizing

master
David 4 роки тому
джерело
коміт
d8c6c0e53b
1 змінених файлів з 25 додано та 23 видалено
  1. +25
    -23
      src/ChainQueue.java

+ 25
- 23
src/ChainQueue.java Переглянути файл

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

Завантаження…
Відмінити
Зберегти