import java.util.ArrayList;
import java.util.List;
public class StackImplList<E> {
private int size = 0;
private int maxSize = 0;
private List<E> list = new ArrayList<>();
public StackImplList(int maxSize) {
this.maxSize = maxSize;
}
E pop() {
if(!isEmpty()) {
size --;
return list.get(size);
}
return null;
}
int size() {
return size;
}
boolean push(E value) {
if(!isFull()) {
list.add(value);
size ++;
return true;
}
return false;
}
boolean isEmpty() {
return size == 0;
}
boolean isFull() {
return size == maxSize;
}
public static void main(String... args) {
StackImplList<Integer> stack = new StackImplList<>(3);
stack.push(1);
stack.push(2);
stack.push(3);
stack.push(4);
System.out.println(stack.pop());
System.out.println(stack.pop());
System.out.println(stack.pop());
System.out.println(stack.pop());
stack.push(1);
stack.push(2);
stack.push(3);
stack.push(4);
System.out.println(stack.pop());
System.out.println(stack.pop());
System.out.println(stack.pop());
System.out.println(stack.pop());
}
}