From cf3946616407cafd11842b31516860cc03ebde41 Mon Sep 17 00:00:00 2001 From: Seongwon Im Date: Mon, 28 May 2018 11:09:22 +0900 Subject: [PATCH] fix stack --- DataStructures/Stacks/Stacks.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/DataStructures/Stacks/Stacks.java b/DataStructures/Stacks/Stacks.java index 2861ef5c..455c67e8 100644 --- a/DataStructures/Stacks/Stacks.java +++ b/DataStructures/Stacks/Stacks.java @@ -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--]; } /**