Skip to content

Commit d7eed5b

Browse files
committed
Migrate ReverseStackUsingRecursion tests into ReverseStackTest (#6474)
1 parent 0ff2c06 commit d7eed5b

File tree

5 files changed

+11
-182
lines changed

5 files changed

+11
-182
lines changed

.devcontainer/Dockerfile

Lines changed: 0 additions & 25 deletions
This file was deleted.

.devcontainer/devcontainer.json

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/main/java/com/thealgorithms/datastructures/stacks/ReverseStack.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,19 @@ private ReverseStack() {
3737
*
3838
* @param stack the stack to reverse; should not be null
3939
*/
40-
public static void reverseStack(Stack<Integer> stack) {
41-
if (stack.isEmpty()) {
42-
return;
43-
}
44-
45-
int element = stack.pop();
46-
reverseStack(stack);
47-
insertAtBottom(stack, element);
40+
public static void reverseStack(Stack<Integer> stack) {
41+
if (stack == null) {
42+
throw new IllegalArgumentException("Stack cannot be null");
43+
}
44+
if (stack.isEmpty()) {
45+
return;
4846
}
4947

48+
int element = stack.pop();
49+
reverseStack(stack);
50+
insertAtBottom(stack, element);
51+
}
52+
5053
/**
5154
* Inserts the specified element at the bottom of the stack.
5255
*

src/main/java/com/thealgorithms/others/ReverseStackUsingRecursion.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/test/java/com/thealgorithms/others/ReverseStackUsingRecursionTest.java

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)