fix stack
This commit is contained in:
parent
ad0e95cdc6
commit
cf39466164
@ -53,18 +53,16 @@ class Stack{
|
||||
* @return value popped off the Stack
|
||||
*/
|
||||
public int pop(){
|
||||
if(!isEmpty()){ //Checks for an empty stack
|
||||
return stackArray[top--];
|
||||
if(isEmpty()){ //Checks for an empty stack
|
||||
System.out.println("The stack is already empty");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(top < maxSize/4){
|
||||
resize(maxSize/2);
|
||||
return pop();// don't forget pop after resizing
|
||||
}
|
||||
else{
|
||||
System.out.println("The stack is already empty");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return stackArray[top--];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user