diff --git a/src/ChainQueue.java b/src/ChainQueue.java index dec4f0b..904ed50 100644 --- a/src/ChainQueue.java +++ b/src/ChainQueue.java @@ -35,15 +35,23 @@ public class ChainQueue implements Queue { } } - Node first; // first item of the queue + private Node first; // first item of the queue + + public Node getFirst() { + return first; + } + + public void setFirst(Node first) { + this.first = first; + } @Override public boolean add(E input) { // Übergeben der "Data" - if (first == null) { // is the first empty? - first = new Node(input); // yes? -> insert the node here + if (getFirst() == null) { // is the first empty? + setFirst(new Node(input)); // yes? -> insert the node here return true; } - return addNode(input, first); // no? -> goto addNode() + return addNode(input, getFirst()); // no? -> goto addNode() } private boolean addNode(E input, Node n) { // run through the queue and find the first "place" which is empty @@ -56,7 +64,7 @@ public class ChainQueue implements Queue { @Override public int size() { // run through the queue and count the size - Node temp = first; + Node temp = getFirst(); int size = 0; while (temp != null) { size++; @@ -76,9 +84,9 @@ public class ChainQueue implements Queue { @Override public boolean contains(Object o) { // does object o exist in our queue? - Node temp = first; + Node temp = getFirst(); for (int i = 0; i < this.size(); i++) { - if (first.getData().equals(o)) { + if (getFirst().getData().equals(o)) { return true; } temp = temp.getNext(); @@ -145,8 +153,8 @@ public class ChainQueue implements Queue { public E poll() { // poll next from queue and remove the first E temp = null; if (!this.isEmpty()) { - temp = first.getData(); - first = first.getNext(); + temp = getFirst().getData(); + setFirst(getFirst().getNext()); } return temp; } @@ -159,9 +167,8 @@ public class ChainQueue implements Queue { @Override public E peek() { // only "see" into the queue and do not remove anything if (!this.isEmpty()) { - return first.getData(); + return getFirst().getData(); } return null; } - } \ No newline at end of file