This is the code i have for my stack program:
public class MyStack {
private int top;
private int[] store;
Stack(int capacity) {
if (capacity <= 0)
throw new IllegalArgumentException("Stack's capacity must be positive");
store = new int[capacity];
top = -1;
}
void push(int value) {
if (top == store.length)
throw new StackException("Stack's underlying storage is overflow");
top++;
store[top] = value;
}
int peek() {
if (top == -1)
throw new StackException("Stack is empty");
return store[top];
}
void pop() {
if (top == -1)
throw new StackException("Stack is empty");
top--;
}
boolean isEmpty() {
return (top == -1);
}
public class StackException extends RuntimeException {
public StackException(String message) {
super(message);
}
}
}
I now have to produce its main method, which demonstrates the axioms used such as pop,push etc
any ideas? thanks