[CODE lang="java" title="StackSpeicher"]public class StackSpeicher {
private final static int MAX_HOEHE = 10;
private int aktuelleHoehe = 0;
public void push(String daten) throws OverflowException{
if (aktuelleHoehe == MAX_HOEHE)
throw new OverflowException();
Knoten knoten = new Knoten(daten,obersterKnoten);
obersterKnoten = knoten;
aktuelleHoehe++;
}
public String pop() throws UnderflowException{
if (aktuelleHoehe == 0){
throw new UnderflowException();
}
public String peek() throws UnderflowException{
if (aktuelleHoehe == 0){
throw new UnderflowException();
}
return obersterKnoten.getData();
}
}[/CODE]
[CODE lang="java" title="UE"]public class UnderflowException extends Exception{
public UnderflowException(){
System.out.println("Der Stapel ist leer!");
}
}
[/CODE]
[CODE lang="java" title="OE"]public class OverflowException extends Exception {
public OverflowException(){
System.out.println("Der Stack ist voll");
}
}[/CODE]
Guten Tag zusammen.
Wir mussten einen Stack programmieren und ich würde gerne eure Meinung hören.
Sollte ich noch etwas hinzufügen oder etwas ändern?
Außerdem möchte Java bei mir "obersterKnoten" nicht erkennen sowie auch "Knoten". Woran könnte das liegen ?
Wir können das schlecht beurteilen, wenn wir die Klasse Knoten nicht kennen.
Gibt es eine solche Klasse überhaupt und wo liegt sie? Möglicherweise musst du sie importieren.
Und ein Member anlegen:
Wir können das schlecht beurteilen, wenn wir die Klasse Knoten nicht kennen.
Gibt es eine solche Klasse überhaupt und wo liegt sie? Möglicherweise musst du sie importieren.
Und ein Member anlegen:
In this tutorial, you will learn while loop in java with the help of examples. Similar to for loop, the while loop is used to execute a set of statements repeatedly until the specified condition returns false. Syntax of while loop while(condition) { statement(s); //block of code } The block of...
In this tutorial, you will learn while loop in java with the help of examples. Similar to for loop, the while loop is used to execute a set of statements repeatedly until the specified condition returns false. Syntax of while loop while(condition) { statement(s); //block of code } The block of...