Merge pull request #447 from dnjsndnjs/stack

fix stack
This commit is contained in:
Christian Bender 2018-06-07 22:24:16 +02:00 committed by GitHub
commit 4733a63f60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -53,18 +53,16 @@ class Stack{
* @return value popped off the Stack * @return value popped off the Stack
*/ */
public int pop(){ public int pop(){
if(!isEmpty()){ //Checks for an empty stack if(isEmpty()){ //Checks for an empty stack
return stackArray[top--]; System.out.println("The stack is already empty");
return -1;
} }
if(top < maxSize/4){ if(top < maxSize/4){
resize(maxSize/2); 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--];
} }
/** /**