Browse Source

implemented methods

master
David 2 years ago
parent
commit
4b2e89e5ed
1 changed files with 49 additions and 15 deletions
  1. +49
    -15
      src/ChainQueue.java

+ 49
- 15
src/ChainQueue.java View File

@@ -7,49 +7,83 @@ public class ChainQueue<E> implements Queue<E> {

private class Node<E> {

E data;
Node<E> next;
private E data;
private Node<E> next;

public Node<E> getNext() {
return next;
}

public E getData() {
return data;
}

public void setData(E data) {
this.data = data;
}

public void setNext(Node<E> next) {
this.next = next;
}

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

}

}

Node<E> first;
Node<E> node;

@Override
public boolean add(E arg0) {
if (first == null) {
first = new Node(arg0);
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
return true;
}
return addNode(arg0, first);
return addNode(input, node); // Andernfalls die Schlage durchlaufen und dort einfügen

}

private boolean addNode(E arg, Node n) {
if (n == null) {
n = new Node(arg);
private boolean addNode(E input, Node n) {
if (n.getNext() == null) {
n.setNext(new Node(input));
return true;
}
if (n.next == null) {
n.next = new Node(arg);
}
return true;
return addNode(input, n.getNext());

}

@Override
public int size() {
return 0;
Node temp = node;
int size = 0;
while (temp != null) {
size++;
temp = temp.getNext();
}
return size;
}


@Override
public boolean isEmpty() {
if (this.size() == 0) {
return true;
}
return false;
}

@Override
public boolean contains(Object o) {
Node temp = node;

for (int i = 0; i < this.size(); i++) {
if (node.getData().equals(o)) {
return true;
}
temp = temp.getNext();
}
return false;
}



Loading…
Cancel
Save