如果插槽已满,我需要将数组中的插槽数加倍。我的代码目前位于我的层次结构是
public class Stack {
Object filearray[]= new Object [5];
public Object push(element) {
if (filearray[filearray.length - 1] != null) {
Object temp_array[] = new Object[filearray.length*2];
int origonal = filearray.length*2;
//adding the element that the user passed in
temp_array[0] = element;
for(int i =0; i<filearray.length;i++) {
temp_array[i+1] =filearray[i];
}
//wiping the filearray clear
Object filearray[] = new Object [origonal];
for (int i=0; i<temp_array.length; i ++) {
filearray [i]=temp_array[i];
}
return filearray;
}
}
}