/** * Beschreiben Sie hier die Klasse Stack. * * @author (Ihr Name) * @version (eine Versionsnummer oder ein Datum) */ public class Stack { public Node first; public Stack(){ } public boolean isEmpty(){ if(first == null){ return true; } return false; } public void push (T neu) { Node n = new Node(neu);//Neue Node mit Zahl "neu " anlegen //Überprüfe ob die liste leer ist if(first == null){ //setze neue node als erster Eintrag first = n; } else { Node current = first; while(current.next != null){ current = current.next; } current.setNext(n); } //current ist jetzt der letzte Eintrag //setze neue Node als Nachfolger von bisher letztem Eintrag } public int laenge(){ Node current = first; int laenge = 0; while(current != null){ current = current.next; laenge++; } return laenge; } public T pop(){ if(first == null){ return null; } else{ Node current = first; first = first.next; return current.wert; } } public T top(){ return first.wert; } }