Skip to content

Commit 2571ee3

Browse files
author
albinsabu2023
committed
fixed build issues
1 parent 487d6ad commit 2571ee3

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.thealgorithms.datastructures.lists;
22

3-
public class CreateAndDetectLoop {
3+
public final class CreateAndDetectLoop {
44

55
// Node class representing a single node in the linked list
6-
public static class Node {
6+
private CreateAndDetectLoop() {
7+
throw new UnsupportedOperationException("Utility class");
8+
}
9+
static final class Node {
710
int data;
811
Node next;
912

@@ -34,8 +37,8 @@ static void createLoop(Node head, int position1, int position2) {
3437
Node node1 = head; // node at position1
3538
Node node2 = head; // node at position2
3639

37-
int count1 = 1, count2 = 1;
38-
40+
int count1 = 1;
41+
int count2 = 1;
3942
// Traverse to find node at position1
4043
while (count1 < position1 && node1 != null) {
4144
node1 = node1.next;

src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.thealgorithms.datastructures.lists;
22

3-
import static org.junit.jupiter.api.Assertions.*;
3+
import static org.junit.jupiter.api.Assertions.assertFalse;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
46
import org.junit.jupiter.api.BeforeEach;
57
import org.junit.jupiter.api.Test;
68

7-
public class CreateAndDetectLoopTest {
9+
public class CreateAndDetectLoopTest {
810

911
private CreateAndDetectLoop.Node head;
1012

@@ -26,13 +28,13 @@ void setUp() {
2628
}
2729

2830
@Test
29-
void testDetectLoop_NoLoop() {
31+
void testDetectLoopNoLoop() {
3032
// Test when no loop exists
3133
assertFalse(CreateAndDetectLoop.detectLoop(head), "There should be no loop.");
3234
}
3335

3436
@Test
35-
void testCreateAndDetectLoop_LoopExists() {
37+
void testCreateAndDetectLoopLoopExists() {
3638
// Create a loop between position 2 (node with value 2) and position 5 (node with value 5)
3739
CreateAndDetectLoop.createLoop(head, 2, 5);
3840

@@ -41,7 +43,7 @@ void testCreateAndDetectLoop_LoopExists() {
4143
}
4244

4345
@Test
44-
void testCreateLoop_InvalidPosition() {
46+
void testCreateLoopInvalidPosition() {
4547
// Create loop with invalid positions
4648
CreateAndDetectLoop.createLoop(head, 0, 0);
4749

@@ -50,7 +52,7 @@ void testCreateLoop_InvalidPosition() {
5052
}
5153

5254
@Test
53-
void testCreateLoop_SelfLoop() {
55+
void testCreateLoopSelfLoop() {
5456
// Create a self-loop at position 3 (node with value 3)
5557
CreateAndDetectLoop.createLoop(head, 3, 3);
5658

@@ -59,7 +61,7 @@ void testCreateLoop_SelfLoop() {
5961
}
6062

6163
@Test
62-
void testCreateLoop_NoChangeForNonExistentPositions() {
64+
void testCreateLoopNoChangeForNonExistentPositions() {
6365
// Create a loop with positions that don't exist in the linked list
6466
CreateAndDetectLoop.createLoop(head, 10, 20);
6567

0 commit comments

Comments
 (0)