Hej, od kilkunastu dni uczę się programowania w Javie
Próbuję napisać stos, ale mi nie działa. Może ktoś znajdzie błąd i chciałby powiedziec
class Stack
{
int MAX = 25, int top, int a[] = new int[MAX];
boolean empty()
{
return (top < 0);
}
Stack()
{
top = -1;
}
boolean push(int x)
{
if (top >= (MAX - 1)) {
throw new Exception();
}
else {
a[top++] = x;
return true;
}
}
int pop()
{
if (top < 0) {
throw new Exception();
}
else {
return top[top - 1];
}
}
int peek()
{
if (top < 0) {
throw new Exception();
}
else {
return a[top];
}
}
}
class Main {
public static void main(String args[]) {
Stack s = new Stack();
s.push(10);
s.push(20);
s.push(30);
System.out.println(s.pop());
}
}