import java.util.Arrays;
public class Ex1 {
//implementing methods getSize, peek, push, pop, isEmpty and toString
final int CAPACITY = 100;
int size;
private E[] array = (E[]) new Object[CAPACITY];
public Ex1() {
}
public int getSize(){
return size;
}
public E peek(){
if(size == 0)
return null;
else
return array[size-1];
}
public void push(E o){
array[size++] = o;
if (size == CAPACITY){
E[] temp = (E[]) new Object[CAPACITY*2];
System.arraycopy(array, 0, temp, 0, array.length);
array = temp;
}
}
public E pop(){
if(size==0)
return null;
else
return array[--size];
}
public boolean isEmpty(){
return size==0;
}
public String toString(){
return "stack: "+Arrays.toString(array);
}
}
import java.util.Arrays;
public class Ex1 {
//implementing methods getSize, peek, push, pop, isEmpty and toString
final int CAPACITY = 100;
int size;
private E[] array = (E[]) new Object[CAPACITY];
}