Skip to content

Commit f660762

Browse files
Merge branch 'master' into dependabot/github_actions/dot-github/workflows/actions/setup-java-5
2 parents 00f2e67 + 3961b1d commit f660762

File tree

4 files changed

+9
-102
lines changed

4 files changed

+9
-102
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ private ReverseStack() {
3838
* @param stack the stack to reverse; should not be null
3939
*/
4040
public static void reverseStack(Stack<Integer> stack) {
41+
if (stack == null) {
42+
throw new IllegalArgumentException("Stack cannot be null");
43+
}
4144
if (stack.isEmpty()) {
4245
return;
4346
}

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

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

src/test/java/com/thealgorithms/datastructures/stacks/ReverseStackTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package com.thealgorithms.datastructures.stacks;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
45
import static org.junit.jupiter.api.Assertions.assertTrue;
56

67
import java.util.Stack;
78
import org.junit.jupiter.api.Test;
89

910
class ReverseStackTest {
1011

12+
@Test
13+
void testReverseNullStack() {
14+
assertThrows(IllegalArgumentException.class, () -> ReverseStack.reverseStack(null), "Reversing a null stack should throw an IllegalArgumentException.");
15+
}
16+
1117
@Test
1218
void testReverseEmptyStack() {
1319
Stack<Integer> stack = new Stack<>();

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

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

0 commit comments

Comments
 (0)