diff --git a/src/ChainQueue.java b/src/ChainQueue.java index 5ba89b7..1a225a2 100644 --- a/src/ChainQueue.java +++ b/src/ChainQueue.java @@ -33,15 +33,15 @@ public class ChainQueue implements Queue { } - Node node; // first item + Node first; // first item of the queue @Override public boolean add(E input) { // Übergeben der "Data" - if (node == null) { // Ist das Erste der Schlange leer? - node = new Node(input); // Ja? Direkt einfügen + if (first == null) { // is the first empty? + first = new Node(input); // yes? -> return true; } - return addNode(input, node); // Andernfalls die Schlage durchlaufen und dort einfügen + return addNode(input, first); // Andernfalls die Schlage durchlaufen und dort einfügen } @@ -55,8 +55,8 @@ public class ChainQueue implements Queue { } @Override - public int size() { - Node temp = node; + public int size() { // run through the queue and count the size + Node temp = first; int size = 0; while (temp != null) { size++; @@ -67,7 +67,7 @@ public class ChainQueue implements Queue { @Override - public boolean isEmpty() { + public boolean isEmpty() { // is the queue empty? -> size == 0 if (this.size() == 0) { return true; } @@ -75,11 +75,10 @@ public class ChainQueue implements Queue { } @Override - public boolean contains(Object o) { - Node temp = node; - + public boolean contains(Object o) { // does object o exist in our queue? + Node temp = first; for (int i = 0; i < this.size(); i++) { - if (node.getData().equals(o)) { + if (first.getData().equals(o)) { return true; } temp = temp.getNext(); @@ -143,11 +142,11 @@ public class ChainQueue implements Queue { } @Override - public E poll() { + public E poll() { // poll next from queue and remove the first E temp = null; if (!this.isEmpty()) { - temp = node.getData(); - node = node.getNext(); + temp = first.getData(); + first = first.getNext(); } return temp; } @@ -158,9 +157,9 @@ public class ChainQueue implements Queue { } @Override - public E peek() { + public E peek() { // only "see" into the queue and do not remove anything if (!this.isEmpty()) { - return node.getData(); + return first.getData(); } return null; }