commit
dba791e515
@ -43,6 +43,7 @@ class Stack{
|
|||||||
stackArray[top] = value;
|
stackArray[top] = value;
|
||||||
}else{
|
}else{
|
||||||
resize(maxSize*2);
|
resize(maxSize*2);
|
||||||
|
push(value);// don't forget push after resizing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +59,7 @@ class Stack{
|
|||||||
|
|
||||||
if(top < maxSize/4){
|
if(top < maxSize/4){
|
||||||
resize(maxSize/2);
|
resize(maxSize/2);
|
||||||
|
return pop();// don't forget pop after resizing
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
System.out.println("The stack is already empty");
|
System.out.println("The stack is already empty");
|
||||||
@ -80,9 +82,11 @@ class Stack{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void resize(int newSize){
|
private void resize(int newSize){
|
||||||
private int[] transferArray = new int[newSize];
|
//private int[] transferArray = new int[newSize]; we can't put modifires here !
|
||||||
|
int[] transferArray = new int[newSize];
|
||||||
|
|
||||||
for(int i = 0; i < stackArray.length(); i++){
|
//for(int i = 0; i < stackArray.length(); i++){ the length isn't a method .
|
||||||
|
for(int i = 0; i < stackArray.length; i++){
|
||||||
transferArray[i] = stackArray[i];
|
transferArray[i] = stackArray[i];
|
||||||
stackArray = transferArray;
|
stackArray = transferArray;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user