public interface Stack<T> {
void push(T item);
T top();
void pop();
}
class StackIML implements Stack<T> {
private T[] items;
private int capacity;
private size;
public StackIML(int capacity) {
this.items = new T[capacity];
this.size = 0;
this.capacity = capacity;
}
@Override
public void push(T item) {
items[size++] = item;
}
@Override
public T top() {
return items[size-1];
}
@Override
public void pop() {
this.size = size - 1;
}
}
Comments
Leave a comment