From d8c6c0e53b2ac7d17b36a4895fe84e99632422c6 Mon Sep 17 00:00:00 2001 From: David Wurm Date: Mon, 25 Nov 2019 22:56:02 +0100 Subject: [PATCH] restructured code, finalizing --- src/ChainQueue.java | 48 +++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/ChainQueue.java b/src/ChainQueue.java index 23cc454..e497b13 100644 --- a/src/ChainQueue.java +++ b/src/ChainQueue.java @@ -94,6 +94,31 @@ public class ChainQueue implements Queue { 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 iterator() { return null; @@ -148,27 +173,4 @@ public class ChainQueue implements Queue { 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; - } } \ No newline at end of file