Browse Source

added add

master
David 2 years ago
parent
commit
d856da2c13
1 changed files with 34 additions and 8 deletions
  1. +34
    -8
      src/ChainQueue.java

+ 34
- 8
src/ChainQueue.java View File

@@ -4,6 +4,40 @@ import java.util.Queue;


public class ChainQueue<E> implements Queue<E> {

private class Node<E> {

E data;
Node<E> next;

public Node(E data) {
this.data = data;
}

}

Node<E> 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<E> implements Queue<E> {
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<E> implements Queue<E> {
return null;
}

private class Node<E> {

}
}

Loading…
Cancel
Save