Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix formatting for ReverseStack and test files
  • Loading branch information
VickySource committed Aug 21, 2025
commit 4aa527e72e2c7c92dc9519f4f49c040706ad83af
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,18 @@ private ReverseStack() {
*
* @param stack the stack to reverse; should not be null
*/
public static void reverseStack(Stack<Integer> stack) {
if (stack == null) {
throw new IllegalArgumentException("Stack cannot be null");
}
if (stack.isEmpty()) {
return;
}

int element = stack.pop();
reverseStack(stack);
insertAtBottom(stack, element);
}
public static void reverseStack(Stack<Integer> stack) {
if (stack == null) {
throw new IllegalArgumentException("Stack cannot be null");
}
if (stack.isEmpty()) {
return;
}

int element = stack.pop();
reverseStack(stack);
insertAtBottom(stack, element);
}

/**
* Inserts the specified element at the bottom of the stack.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
class ReverseStackTest {

@Test
void testReverseNullStack() {
assertThrows(IllegalArgumentException.class,
() -> ReverseStack.reverseStack(null),
"Reversing a null stack should throw an IllegalArgumentException.");
}

void testReverseNullStack() {
assertThrows(IllegalArgumentException.class, () -> ReverseStack.reverseStack(null), "Reversing a null stack should throw an IllegalArgumentException.");
}

@Test
void testReverseEmptyStack() {
Expand Down