/**
  *
  * Beschreibung
  *
  * @version 1.0 vom 26.11.2019
  * @author  Carsten Wieneke
  */

public class Queue<Inhaltstyp> {
  
  // Anfang Attribute
  private Knoten<Inhaltstyp> kopf;
  private Knoten<Inhaltstyp> ende;
  // Ende Attribute
  
  public Queue() {
    this.kopf = null;
    this.ende = null;
  }
  
  // Anfang Methoden
  public boolean isEmpty() {
    return (kopf == null);
  }
  
  public Inhaltstyp head() {
    return this.kopf.gibInhalt();
  }
  
  public void dequeue() {
    if (!this.isEmpty()) {
      kopf = kopf.naechsterKnoten();
    } 
    if (kopf == null) { // Sonderfall: es war nur ein Element in der Schlange
      ende = null;
    } // end of if
  }
  
  public void enqueue(Inhaltstyp inhalt) {
    if (!this.isEmpty()) {
      Knoten<Inhaltstyp> neu = new Knoten<Inhaltstyp>(inhalt);
      this.ende.setzeNachfolger(neu);
      this.ende = neu;
    } 
    else{
      Knoten<Inhaltstyp> neu = new Knoten<Inhaltstyp>(inhalt);
      this.ende = neu;
      this.kopf = neu;
    }
  }
      
} // end of Schlange
