Skip to content

Commit db4e0c3

Browse files
style: apply clang-format to fix formatting issues
1 parent 41020e5 commit db4e0c3

File tree

2 files changed

+103
-103
lines changed

2 files changed

+103
-103
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.
5-
* Supports basic operations like push, pop, peek, and isEmpty.
4+
* A class that implements a Stack using a singly linked list. Supports basic
5+
* 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
}

src/test/java/com/thealgorithms/stacks/StackUsingLinkedListTest.java

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,66 +6,66 @@
66
/**
77
* Test class for StackUsingLinkedList.
88
*
9-
* This class contains unit tests to verify the correctness
10-
* of stack operations such as push, pop, peek, and isEmpty.
9+
* This class contains unit tests to verify the correctness of stack operations
10+
* such as push, pop, peek, and isEmpty.
1111
*
1212
* Reference: https://www.geeksforgeeks.org/stack-using-linked-list/
1313
*/
1414
class StackUsingLinkedListTest {
1515

16-
/**
17-
* Test push and pop operations
18-
*/
19-
@Test
20-
void testPushAndPop() {
21-
StackUsingLinkedList stack = new StackUsingLinkedList();
22-
stack.push(10);
23-
stack.push(20);
16+
/**
17+
* Test push and pop operations
18+
*/
19+
@Test
20+
void testPushAndPop() {
21+
StackUsingLinkedList stack = new StackUsingLinkedList();
22+
stack.push(10);
23+
stack.push(20);
2424

25-
assertEquals(20, stack.pop());
26-
assertEquals(10, stack.pop());
27-
}
25+
assertEquals(20, stack.pop());
26+
assertEquals(10, stack.pop());
27+
}
2828

29-
/**
30-
* Test peek operation
31-
*/
32-
@Test
33-
void testPeek() {
34-
StackUsingLinkedList stack = new StackUsingLinkedList();
35-
stack.push(5);
29+
/**
30+
* Test peek operation
31+
*/
32+
@Test
33+
void testPeek() {
34+
StackUsingLinkedList stack = new StackUsingLinkedList();
35+
stack.push(5);
3636

37-
assertEquals(5, stack.peek());
38-
}
37+
assertEquals(5, stack.peek());
38+
}
3939

40-
/**
41-
* Test isEmpty method
42-
*/
43-
@Test
44-
void testIsEmpty() {
45-
StackUsingLinkedList stack = new StackUsingLinkedList();
40+
/**
41+
* Test isEmpty method
42+
*/
43+
@Test
44+
void testIsEmpty() {
45+
StackUsingLinkedList stack = new StackUsingLinkedList();
4646

47-
assertTrue(stack.isEmpty());
48-
stack.push(1);
49-
assertFalse(stack.isEmpty());
50-
}
47+
assertTrue(stack.isEmpty());
48+
stack.push(1);
49+
assertFalse(stack.isEmpty());
50+
}
5151

52-
/**
53-
* Test pop on empty stack (edge case)
54-
*/
55-
@Test
56-
void testPopOnEmptyStack() {
57-
StackUsingLinkedList stack = new StackUsingLinkedList();
52+
/**
53+
* Test pop on empty stack (edge case)
54+
*/
55+
@Test
56+
void testPopOnEmptyStack() {
57+
StackUsingLinkedList stack = new StackUsingLinkedList();
5858

59-
assertThrows(RuntimeException.class, stack::pop);
60-
}
59+
assertThrows(RuntimeException.class, stack::pop);
60+
}
6161

62-
/**
63-
* Test peek on empty stack (edge case)
64-
*/
65-
@Test
66-
void testPeekOnEmptyStack() {
67-
StackUsingLinkedList stack = new StackUsingLinkedList();
62+
/**
63+
* Test peek on empty stack (edge case)
64+
*/
65+
@Test
66+
void testPeekOnEmptyStack() {
67+
StackUsingLinkedList stack = new StackUsingLinkedList();
6868

69-
assertThrows(RuntimeException.class, stack::peek);
70-
}
69+
assertThrows(RuntimeException.class, stack::peek);
70+
}
7171
}

0 commit comments

Comments
 (0)