We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 419b91d + cf39466 commit 4733a63Copy full SHA for 4733a63
DataStructures/Stacks/Stacks.java
@@ -53,18 +53,16 @@ public void push(int value){
53
* @return value popped off the Stack
54
*/
55
public int pop(){
56
- if(!isEmpty()){ //Checks for an empty stack
57
- return stackArray[top--];
+ if(isEmpty()){ //Checks for an empty stack
+ System.out.println("The stack is already empty");
58
+ return -1;
59
}
60
61
if(top < maxSize/4){
62
resize(maxSize/2);
- return pop();// don't forget pop after resizing
63
- }
64
- else{
65
- System.out.println("The stack is already empty");
66
- return -1;
67
+
+ return stackArray[top--];
68
69
70
/**
0 commit comments