hey guys, vielleicht kann mir hier jemand einen Gefallen tun (wiedermal lol) und das programm untersuchen, mein debugger läuft einfach nicht richtig und ich weiß nicht ob mein programm das macht was ich möchte... Also der Stack soll die Zahlen von 9-999 mit einer for-Schleife ausgeben. Hoffentlich tut mein programm das. Ich hab 2 klassen, bitte Hilfe, schon wieder:
und
danke WIEDERMAL für die Hilfe
Java:
public class Arraystapel1Main {
public static void main(String[] args) {
Arraystapel buli = new Arraystapel(990);
for(int i = 9; i <999; i++){
buli.push(i);
}
while(!buli.isEmpty())
{
System.out.println(buli.top());
buli.pop();
}
}
}
und
Java:
public class Arraystapel {
private Object[]stapi;
private int index, maxIndex;
public Arraystapel (int größe)
{ index = 0;
maxIndex = größe-1;
stapi = new Object [größe];
}
public boolean isEmpty()
{ if (stapi[0]==null)
{
return true;
} else {
return false; }
}
public void push (Object pObject)
{
if (!isFull())
{
stapi[index]=pObject;
index++;
}
else
{
System.out.print("Stapel ist voll");
}
}
public Object top() {
if (!isEmpty())
{
return stapi[index-1];
}
else
{
return null;
}
}
public boolean isFull()
{ if (index == maxIndex+1)
{
return true;
}
else
{
return false;
}
}
public void pop() {
if (!isEmpty())
{
stapi[index-1]=null;
index--;
}
else { System.out.println("Stapel ist leer");
}
}
}