fix stack

This commit is contained in:
Seongwon Im 2018-05-28 11:09:22 +09:00
parent ad0e95cdc6
commit cf39466164

View File

@ -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--];
}
/**