Skip to content

Commit dba791e

Browse files
author
Christian Bender
authored
Merge pull request TheAlgorithms#399 from khalil2535/master
Update Stacks.java
2 parents 9ad263f + 9ac82a1 commit dba791e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Data Structures/Stacks/Stacks.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public void push(int value){
4343
stackArray[top] = value;
4444
}else{
4545
resize(maxSize*2);
46+
push(value);// don't forget push after resizing
4647
}
4748
}
4849

@@ -58,6 +59,7 @@ public int pop(){
5859

5960
if(top < maxSize/4){
6061
resize(maxSize/2);
62+
return pop();// don't forget pop after resizing
6163
}
6264
else{
6365
System.out.println("The stack is already empty");
@@ -80,9 +82,11 @@ public int peek(){
8082
}
8183

8284
private void resize(int newSize){
83-
private int[] transferArray = new int[newSize];
85+
//private int[] transferArray = new int[newSize]; we can't put modifires here !
86+
int[] transferArray = new int[newSize];
8487

85-
for(int i = 0; i < stackArray.length(); i++){
88+
//for(int i = 0; i < stackArray.length(); i++){ the length isn't a method .
89+
for(int i = 0; i < stackArray.length; i++){
8690
transferArray[i] = stackArray[i];
8791
stackArray = transferArray;
8892
}

0 commit comments

Comments
 (0)