Skip to content

Commit ca2cdfc

Browse files
style: fix formatting to satisfy clang-format and checkstyle
1 parent bedd1ce commit ca2cdfc

File tree

2 files changed

+105
-104
lines changed

2 files changed

+105
-104
lines changed
Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,70 @@
11
package com.thealgorithms.stacks;
22

33
/**
4-
* A class that implements a Stack using a singly linked list. Supports basic
5-
* operations like push, pop, peek, and isEmpty.
4+
* A class that implements a Stack using a singly linked list.
5+
* Supports basic operations like push, pop, peek, and isEmpty.
66
*
77
* Reference: https://www.geeksforgeeks.org/stack-using-linked-list/
88
*/
99
public class StackUsingLinkedList {
1010

11-
/**
12-
* Node class representing each element in the stack
13-
*/
14-
private static class Node {
15-
int data;
16-
Node next;
11+
/**
12+
* Node class representing each element in the stack
13+
*/
14+
private static class Node {
15+
int data;
16+
Node next;
1717

18-
Node(int data) {
19-
this.data = data;
20-
}
21-
}
18+
Node(int data) {
19+
this.data = data;
20+
}
21+
}
2222

23-
private Node top;
23+
private Node top;
2424

25-
/**
26-
* Push an element onto the stack
27-
*
28-
* @param value the value to push
29-
*/
30-
public void push(int value) {
31-
Node newNode = new Node(value);
32-
newNode.next = top;
33-
top = newNode;
34-
}
25+
/**
26+
* Push an element onto the stack
27+
*
28+
* @param value the value to push
29+
*/
30+
public void push(int value) {
31+
Node newNode = new Node(value);
32+
newNode.next = top;
33+
top = newNode;
34+
}
3535

36-
/**
37-
* Remove and return the top element of the stack
38-
*
39-
* @return top element
40-
*/
41-
public int pop() {
42-
if (top == null) {
43-
throw new RuntimeException("Stack is empty");
44-
}
45-
int value = top.data;
46-
top = top.next;
47-
return value;
48-
}
36+
/**
37+
* Remove and return the top element of the stack
38+
*
39+
* @return top element
40+
*/
41+
public int pop() {
42+
if (top == null) {
43+
throw new RuntimeException("Stack is empty");
44+
}
45+
int value = top.data;
46+
top = top.next;
47+
return value;
48+
}
4949

50-
/**
51-
* Return the top element without removing it
52-
*
53-
* @return top element
54-
*/
55-
public int peek() {
56-
if (top == null) {
57-
throw new RuntimeException("Stack is empty");
58-
}
59-
return top.data;
60-
}
50+
/**
51+
* Return the top element without removing it
52+
*
53+
* @return top element
54+
*/
55+
public int peek() {
56+
if (top == null) {
57+
throw new RuntimeException("Stack is empty");
58+
}
59+
return top.data;
60+
}
6161

62-
/**
63-
* Check if the stack is empty
64-
*
65-
* @return true if empty, false otherwise
66-
*/
67-
public boolean isEmpty() {
68-
return top == null;
69-
}
62+
/**
63+
* Check if the stack is empty
64+
*
65+
* @return true if empty, false otherwise
66+
*/
67+
public boolean isEmpty() {
68+
return top == null;
69+
}
7070
}
Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,75 @@
11
package com.thealgorithms.stacks;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
45
import static org.junit.jupiter.api.Assertions.assertThrows;
56
import static org.junit.jupiter.api.Assertions.assertTrue;
6-
import static org.junit.jupiter.api.Assertions.assertFalse;
7+
78
import org.junit.jupiter.api.Test;
89

910
/**
1011
* Test class for StackUsingLinkedList.
1112
*
12-
* This class contains unit tests to verify the correctness of stack operations
13-
* such as push, pop, peek, and isEmpty.
13+
* This class contains unit tests to verify the correctness
14+
* of stack operations such as push, pop, peek, and isEmpty.
1415
*
1516
* Reference: https://www.geeksforgeeks.org/stack-using-linked-list/
1617
*/
1718
class StackUsingLinkedListTest {
1819

19-
/**
20-
* Test push and pop operations
21-
*/
22-
@Test
23-
void testPushAndPop() {
24-
StackUsingLinkedList stack = new StackUsingLinkedList();
25-
stack.push(10);
26-
stack.push(20);
20+
/**
21+
* Test push and pop operations
22+
*/
23+
@Test
24+
void testPushAndPop() {
25+
StackUsingLinkedList stack = new StackUsingLinkedList();
26+
stack.push(10);
27+
stack.push(20);
2728

28-
assertEquals(20, stack.pop());
29-
assertEquals(10, stack.pop());
30-
}
29+
assertEquals(20, stack.pop());
30+
assertEquals(10, stack.pop());
31+
}
3132

32-
/**
33-
* Test peek operation
34-
*/
35-
@Test
36-
void testPeek() {
37-
StackUsingLinkedList stack = new StackUsingLinkedList();
38-
stack.push(5);
33+
/**
34+
* Test peek operation
35+
*/
36+
@Test
37+
void testPeek() {
38+
StackUsingLinkedList stack = new StackUsingLinkedList();
39+
stack.push(5);
3940

40-
assertEquals(5, stack.peek());
41-
}
41+
assertEquals(5, stack.peek());
42+
}
4243

43-
/**
44-
* Test isEmpty method
45-
*/
46-
@Test
47-
void testIsEmpty() {
48-
StackUsingLinkedList stack = new StackUsingLinkedList();
44+
/**
45+
* Test isEmpty method
46+
*/
47+
@Test
48+
void testIsEmpty() {
49+
StackUsingLinkedList stack = new StackUsingLinkedList();
4950

50-
assertTrue(stack.isEmpty());
51-
stack.push(1);
52-
assertFalse(stack.isEmpty());
53-
}
51+
assertTrue(stack.isEmpty());
52+
stack.push(1);
53+
assertFalse(stack.isEmpty());
54+
}
5455

55-
/**
56-
* Test pop on empty stack (edge case)
57-
*/
58-
@Test
59-
void testPopOnEmptyStack() {
60-
StackUsingLinkedList stack = new StackUsingLinkedList();
56+
/**
57+
* Test pop on empty stack (edge case)
58+
*/
59+
@Test
60+
void testPopOnEmptyStack() {
61+
StackUsingLinkedList stack = new StackUsingLinkedList();
6162

62-
assertThrows(RuntimeException.class, stack::pop);
63-
}
63+
assertThrows(RuntimeException.class, stack::pop);
64+
}
6465

65-
/**
66-
* Test peek on empty stack (edge case)
67-
*/
68-
@Test
69-
void testPeekOnEmptyStack() {
70-
StackUsingLinkedList stack = new StackUsingLinkedList();
66+
/**
67+
* Test peek on empty stack (edge case)
68+
*/
69+
@Test
70+
void testPeekOnEmptyStack() {
71+
StackUsingLinkedList stack = new StackUsingLinkedList();
7172

72-
assertThrows(RuntimeException.class, stack::peek);
73-
}
73+
assertThrows(RuntimeException.class, stack::peek);
74+
}
7475
}

0 commit comments

Comments
 (0)