commit
4733a63f60
@ -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