AbstrakteDatentypen/Queue.java

38 lines
828 B
Java

public class Queue<T>
{
private Node<T> first;
private Node<T> last;
public Queue(){
this.first = null;
this.last = null;
}
public boolean isEmpty(){
return this.first == null;
}
public void enqueue(T val){
Node<T> added = new Node<T>(val);
Node<T> current = this.first;
if (this.first == null){
this.first = added;
this.last = added;
}
else{
this.last.next = added;
this.last = added;
}
}
public T dequeue (){
if (this.first == null) return null;
T ret = this.first.wert;
this.first = this.first.next;
return ret;
}
public T front (){
if (this.first == null) return null;
return this.first.wert;
}
}