You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);
}
}
The text was updated successfully, but these errors were encountered:
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];
}
The text was updated successfully, but these errors were encountered: