Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.EmptyStackException;
- public class stack_array<T> implements stack{
- private T[] stack;
- private int lastPos = 0;
- private stack_array(int length){
- stack = (T[]) new Object[length];
- }
- public <T> T pop( T[] a) throws EmptyStackException {
- if (this.lastPos < 0){
- throw new EmptyStackException();
- }
- else
- {
- this.lastPos --;
- return (T) stack[lastPos];
- }
- }
- @SuppressWarnings("hiding")
- public void insert(T a){
- if (this.lastPos >= stack.length){
- throw new ArrayIndexOutOfBoundsException();
- }
- else
- {
- this.lastPos ++;
- stack[lastPos] = a;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement