From d856da2c138e0ff5782a92dc1347d99c5da9789f Mon Sep 17 00:00:00 2001 From: David Wurm Date: Mon, 25 Nov 2019 21:38:31 +0100 Subject: [PATCH] added add --- src/ChainQueue.java | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/ChainQueue.java b/src/ChainQueue.java index 72fc365..f6b31e9 100644 --- a/src/ChainQueue.java +++ b/src/ChainQueue.java @@ -4,6 +4,40 @@ import java.util.Queue; public class ChainQueue implements Queue { + + private class Node { + + E data; + Node next; + + public Node(E data) { + this.data = data; + } + + } + + Node first; + + @Override + public boolean add(E arg0) { + if (first == null) { + first = new Node(arg0); + } + return addNode(arg0, first); + + } + + private boolean addNode(E arg, Node n) { + if (n == null) { + n = new Node(arg); + } + if (n.next == null) { + n.next = new Node(arg); + } + return true; + + } + @Override public int size() { return 0; @@ -34,11 +68,6 @@ public class ChainQueue implements Queue { return null; } - @Override - public boolean add(E e) { - return false; - } - @Override public boolean remove(Object o) { return false; @@ -94,7 +123,4 @@ public class ChainQueue implements Queue { return null; } - private class Node { - - } } \ No newline at end of file