From 334bdbb6a624dd3d5ecb654acf4be6cef76d6118 Mon Sep 17 00:00:00 2001 From: albinsabu2023 Date: Fri, 4 Oct 2024 01:33:42 +0530 Subject: [PATCH 1/9] added lengthofloopinlist --- .../lists/LengthOfLoopInList.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/main/java/com/thealgorithms/datastructures/lists/LengthOfLoopInList.java diff --git a/src/main/java/com/thealgorithms/datastructures/lists/LengthOfLoopInList.java b/src/main/java/com/thealgorithms/datastructures/lists/LengthOfLoopInList.java new file mode 100644 index 000000000000..b69129408b2a --- /dev/null +++ b/src/main/java/com/thealgorithms/datastructures/lists/LengthOfLoopInList.java @@ -0,0 +1,76 @@ +package com.thealgorithms.datastructures.lists; + +public class LengthOfLoopInList { + // Inner static Node class + public static class Node { + int data; + Node next; + + Node(int data) { + this.data = data; + this.next = null; + } + } + + // Method to find the length of the loop + public static int findLength(Node slow, Node fast) { + int count = 1; + slow = slow.next; + while (slow != fast) { + slow = slow.next; + count++; + } + return count; + } + + // Method to find the length of the loop in the linked list + public static int lengthOfLoop(Node head) { + Node slow = head; + Node fast = head; + + while (fast != null && fast.next != null) { + slow = slow.next; + fast = fast.next.next; + // If both meet, a loop is found + if (slow == fast) { + return findLength(slow, fast); + } + } + return 0; // No loop found + } + + // Method to create a linked list with a loop of length 5 + public static Node createLinkedListWithLoop() { + Node head = new Node(1); + Node second = new Node(2); + Node third = new Node(3); + Node fourth = new Node(4); + Node fifth = new Node(5); + Node sixth = new Node(6); + Node seventh = new Node(7); + + // Linking nodes together to form a linear list + head.next = second; + second.next = third; + third.next = fourth; + fourth.next = fifth; + fifth.next = sixth; + sixth.next = seventh; + + // Creating a loop: the next of the 7th node points to the 3rd node + seventh.next = third; + + return head; + } + + // Main method to test the functionality + public static void main(String[] args) { + Node head = createLinkedListWithLoop(); + int loopLength = lengthOfLoop(head); + if (loopLength != 0) { + System.out.println("Length of the loop is: " + loopLength); + } else { + System.out.println("No loop found."); + } + } +} From 870d1d6f38bbca26bc4f4d0e9e01e80317ab3af8 Mon Sep 17 00:00:00 2001 From: albinsabu2023 Date: Sat, 5 Oct 2024 02:21:19 +0530 Subject: [PATCH 2/9] updated CreateAndDetectLoop --- .../lists/CreateAndDetectLoop.java | 111 +++++++----------- .../lists/LengthOfLoopInList.java | 76 ------------ 2 files changed, 43 insertions(+), 144 deletions(-) delete mode 100644 src/main/java/com/thealgorithms/datastructures/lists/LengthOfLoopInList.java diff --git a/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java b/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java index 441c95702050..485b88d6a935 100644 --- a/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java +++ b/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java @@ -1,63 +1,65 @@ package com.thealgorithms.datastructures.lists; -import java.util.Scanner; -public final class CreateAndDetectLoop { - private CreateAndDetectLoop() { - } +public class CreateAndDetectLoop { - /** - * Prints the linked list. - * - * @param head head node of the linked list - */ - static void printList(Node head) { - Node cur = head; + // Node class representing a single node in the linked list + public static class Node { + int data; + Node next; - while (cur != null) { - System.out.print(cur.value + " "); - cur = cur.next; + Node(int data) { + this.data = data; + next = null; } } + // Method to create a loop between two specific positions in the linked list /** - * Creates a loop in the linked list. - * - * @see - * - * GeeksForGeeks: Make a loop at K-th position - * @param head head node of the linked list - * @param k position of node where loop is to be created + * Test case that shows the Cycle(loop) in a LinkedList + * Let's take this linked list: + * 1->2->3->4->5->6 + * \______/ + * In this linked list we can see there is a cycle. + * we can create loop by calling createLoop function in main after creating LL + * createLoop(head,2,5); + * to detect there is loop or not we can call detectloop function in main + * detectloop(head); */ - static void createLoop(Node head, int k) { - if (head == null) { + + static void createLoop(Node head, int position1, int position2) { + if (position1 == 0 || position2 == 0) { return; } - Node temp = head; - int count = 1; - while (count < k) { // Traverse the list till the kth node - temp = temp.next; - count++; - } - Node connectedPoint = temp; + Node node1 = head; // node at position1 + Node node2 = head; // node at position2 + + int count1 = 1, count2 = 1; + + // Traverse to find node at position1 + while (count1 < position1 && node1 != null) { + node1 = node1.next; + count1++; + } - while (temp.next != null) { // Traverse remaining nodes - temp = temp.next; + // Traverse to find node at position2 + while (count2 < position2 && node2 != null) { + node2 = node2.next; + count2++; } - temp.next = connectedPoint; // Connect last node to k-th element + // Create a loop by connecting node2's next to node1 + if (node1 != null && node2 != null) { + node2.next = node1; + } } + // Method to detect a loop in the linked list /** * Detects the presence of a loop in the linked list. * - * @see - * - * Floyd's Cycle Detection Algorithm - * - * @param head the head node of the linked list - * + * @see Floyd's Cycle Detection Algorithm * @return true if loop exists else false */ static boolean detectLoop(Node head) { @@ -67,40 +69,13 @@ static boolean detectLoop(Node head) { while (fptr != null && fptr.next != null) { sptr = sptr.next; fptr = fptr.next.next; - if (fptr == sptr) { + if (sptr == fptr) { return true; } } - return false; } +} - public static void main(String[] args) { - SinglyLinkedList singlyLinkedList = new SinglyLinkedList(); - Scanner sc = new Scanner(System.in); - - System.out.println("Enter the number of elements to be inserted: "); - int n = sc.nextInt(); - System.out.printf("Enter the %d elements: %n", n); - while (n-- > 0) { - singlyLinkedList.insert(sc.nextInt()); - } - - System.out.print("Given list: "); - printList(singlyLinkedList.getHead()); - System.out.println(); - - System.out.println("Enter the location to generate loop: "); - int k = sc.nextInt(); - - createLoop(singlyLinkedList.getHead(), k); - if (detectLoop(singlyLinkedList.getHead())) { - System.out.println("Loop found"); - } else { - System.out.println("No loop found"); - } - sc.close(); - } -} diff --git a/src/main/java/com/thealgorithms/datastructures/lists/LengthOfLoopInList.java b/src/main/java/com/thealgorithms/datastructures/lists/LengthOfLoopInList.java deleted file mode 100644 index b69129408b2a..000000000000 --- a/src/main/java/com/thealgorithms/datastructures/lists/LengthOfLoopInList.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.thealgorithms.datastructures.lists; - -public class LengthOfLoopInList { - // Inner static Node class - public static class Node { - int data; - Node next; - - Node(int data) { - this.data = data; - this.next = null; - } - } - - // Method to find the length of the loop - public static int findLength(Node slow, Node fast) { - int count = 1; - slow = slow.next; - while (slow != fast) { - slow = slow.next; - count++; - } - return count; - } - - // Method to find the length of the loop in the linked list - public static int lengthOfLoop(Node head) { - Node slow = head; - Node fast = head; - - while (fast != null && fast.next != null) { - slow = slow.next; - fast = fast.next.next; - // If both meet, a loop is found - if (slow == fast) { - return findLength(slow, fast); - } - } - return 0; // No loop found - } - - // Method to create a linked list with a loop of length 5 - public static Node createLinkedListWithLoop() { - Node head = new Node(1); - Node second = new Node(2); - Node third = new Node(3); - Node fourth = new Node(4); - Node fifth = new Node(5); - Node sixth = new Node(6); - Node seventh = new Node(7); - - // Linking nodes together to form a linear list - head.next = second; - second.next = third; - third.next = fourth; - fourth.next = fifth; - fifth.next = sixth; - sixth.next = seventh; - - // Creating a loop: the next of the 7th node points to the 3rd node - seventh.next = third; - - return head; - } - - // Main method to test the functionality - public static void main(String[] args) { - Node head = createLinkedListWithLoop(); - int loopLength = lengthOfLoop(head); - if (loopLength != 0) { - System.out.println("Length of the loop is: " + loopLength); - } else { - System.out.println("No loop found."); - } - } -} From 487d6adfff16e0ae05de7b7607bb7ea6f7ca5a67 Mon Sep 17 00:00:00 2001 From: albinsabu2023 Date: Mon, 7 Oct 2024 09:58:38 +0530 Subject: [PATCH 3/9] added unit test --- .../lists/CreateAndDetectLoop.java | 3 +- .../lists/CreateAndDetectLoopTest.java | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java diff --git a/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java b/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java index 485b88d6a935..4ec0ac21f3b9 100644 --- a/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java +++ b/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java @@ -1,6 +1,5 @@ package com.thealgorithms.datastructures.lists; - public class CreateAndDetectLoop { // Node class representing a single node in the linked list @@ -15,7 +14,7 @@ public static class Node { } // Method to create a loop between two specific positions in the linked list - /** + /* * Test case that shows the Cycle(loop) in a LinkedList * Let's take this linked list: * 1->2->3->4->5->6 diff --git a/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java b/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java new file mode 100644 index 000000000000..b370a68f1857 --- /dev/null +++ b/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java @@ -0,0 +1,70 @@ +package com.thealgorithms.datastructures.lists; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class CreateAndDetectLoopTest { + + private CreateAndDetectLoop.Node head; + + @BeforeEach + void setUp() { + // Create a linked list: 1 -> 2 -> 3 -> 4 -> 5 -> 6 + head = new CreateAndDetectLoop.Node(1); + CreateAndDetectLoop.Node second = new CreateAndDetectLoop.Node(2); + CreateAndDetectLoop.Node third = new CreateAndDetectLoop.Node(3); + CreateAndDetectLoop.Node fourth = new CreateAndDetectLoop.Node(4); + CreateAndDetectLoop.Node fifth = new CreateAndDetectLoop.Node(5); + CreateAndDetectLoop.Node sixth = new CreateAndDetectLoop.Node(6); + + head.next = second; + second.next = third; + third.next = fourth; + fourth.next = fifth; + fifth.next = sixth; + } + + @Test + void testDetectLoop_NoLoop() { + // Test when no loop exists + assertFalse(CreateAndDetectLoop.detectLoop(head), "There should be no loop."); + } + + @Test + void testCreateAndDetectLoop_LoopExists() { + // Create a loop between position 2 (node with value 2) and position 5 (node with value 5) + CreateAndDetectLoop.createLoop(head, 2, 5); + + // Now test if the loop is detected + assertTrue(CreateAndDetectLoop.detectLoop(head), "A loop should be detected."); + } + + @Test + void testCreateLoop_InvalidPosition() { + // Create loop with invalid positions + CreateAndDetectLoop.createLoop(head, 0, 0); + + // Ensure no loop was created + assertFalse(CreateAndDetectLoop.detectLoop(head), "There should be no loop with invalid positions."); + } + + @Test + void testCreateLoop_SelfLoop() { + // Create a self-loop at position 3 (node with value 3) + CreateAndDetectLoop.createLoop(head, 3, 3); + + // Test if the self-loop is detected + assertTrue(CreateAndDetectLoop.detectLoop(head), "A self-loop should be detected."); + } + + @Test + void testCreateLoop_NoChangeForNonExistentPositions() { + // Create a loop with positions that don't exist in the linked list + CreateAndDetectLoop.createLoop(head, 10, 20); + + // Ensure no loop was created + assertFalse(CreateAndDetectLoop.detectLoop(head), "No loop should be created if positions are out of bounds."); + } +} + From 2571ee31ad5ccfe4e79d9a8c2c395804227efade Mon Sep 17 00:00:00 2001 From: albinsabu2023 Date: Mon, 7 Oct 2024 10:37:24 +0530 Subject: [PATCH 4/9] fixed build issues --- .../lists/CreateAndDetectLoop.java | 11 +++++++---- .../lists/CreateAndDetectLoopTest.java | 16 +++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java b/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java index 4ec0ac21f3b9..19f41599685c 100644 --- a/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java +++ b/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java @@ -1,9 +1,12 @@ package com.thealgorithms.datastructures.lists; -public class CreateAndDetectLoop { +public final class CreateAndDetectLoop { // Node class representing a single node in the linked list - public static class Node { + private CreateAndDetectLoop() { + throw new UnsupportedOperationException("Utility class"); + } + static final class Node { int data; Node next; @@ -34,8 +37,8 @@ static void createLoop(Node head, int position1, int position2) { Node node1 = head; // node at position1 Node node2 = head; // node at position2 - int count1 = 1, count2 = 1; - + int count1 = 1; + int count2 = 1; // Traverse to find node at position1 while (count1 < position1 && node1 != null) { node1 = node1.next; diff --git a/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java b/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java index b370a68f1857..e23befb9dc8b 100644 --- a/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java +++ b/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java @@ -1,10 +1,12 @@ package com.thealgorithms.datastructures.lists; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class CreateAndDetectLoopTest { +public class CreateAndDetectLoopTest { private CreateAndDetectLoop.Node head; @@ -26,13 +28,13 @@ void setUp() { } @Test - void testDetectLoop_NoLoop() { + void testDetectLoopNoLoop() { // Test when no loop exists assertFalse(CreateAndDetectLoop.detectLoop(head), "There should be no loop."); } @Test - void testCreateAndDetectLoop_LoopExists() { + void testCreateAndDetectLoopLoopExists() { // Create a loop between position 2 (node with value 2) and position 5 (node with value 5) CreateAndDetectLoop.createLoop(head, 2, 5); @@ -41,7 +43,7 @@ void testCreateAndDetectLoop_LoopExists() { } @Test - void testCreateLoop_InvalidPosition() { + void testCreateLoopInvalidPosition() { // Create loop with invalid positions CreateAndDetectLoop.createLoop(head, 0, 0); @@ -50,7 +52,7 @@ void testCreateLoop_InvalidPosition() { } @Test - void testCreateLoop_SelfLoop() { + void testCreateLoopSelfLoop() { // Create a self-loop at position 3 (node with value 3) CreateAndDetectLoop.createLoop(head, 3, 3); @@ -59,7 +61,7 @@ void testCreateLoop_SelfLoop() { } @Test - void testCreateLoop_NoChangeForNonExistentPositions() { + void testCreateLoopNoChangeForNonExistentPositions() { // Create a loop with positions that don't exist in the linked list CreateAndDetectLoop.createLoop(head, 10, 20); From 49fbad22b7c41ee55b863e01534ff26b434de3c5 Mon Sep 17 00:00:00 2001 From: albinsabu2023 Date: Mon, 7 Oct 2024 10:54:36 +0530 Subject: [PATCH 5/9] fix lint issues --- .../datastructures/lists/CreateAndDetectLoop.java | 6 +++--- .../datastructures/lists/CreateAndDetectLoopTest.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java b/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java index 19f41599685c..e34f7287d5b9 100644 --- a/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java +++ b/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java @@ -6,7 +6,7 @@ public final class CreateAndDetectLoop { private CreateAndDetectLoop() { throw new UnsupportedOperationException("Utility class"); } - static final class Node { + static final class Node { int data; Node next; @@ -34,8 +34,8 @@ static void createLoop(Node head, int position1, int position2) { return; } - Node node1 = head; // node at position1 - Node node2 = head; // node at position2 + Node node1 = head; + Node node2 = head; int count1 = 1; int count2 = 1; diff --git a/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java b/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java index e23befb9dc8b..4b742e6818ff 100644 --- a/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java +++ b/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java @@ -6,7 +6,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class CreateAndDetectLoopTest { +public class CreateAndDetectLoopTest { private CreateAndDetectLoop.Node head; From 3b5fadba3556ee59e1880d238893f4f47035e6f7 Mon Sep 17 00:00:00 2001 From: albinsabu2023 Date: Mon, 7 Oct 2024 11:00:45 +0530 Subject: [PATCH 6/9] fixed lint --- .../datastructures/lists/CreateAndDetectLoop.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java b/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java index e34f7287d5b9..d9c453694246 100644 --- a/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java +++ b/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java @@ -1,12 +1,12 @@ package com.thealgorithms.datastructures.lists; -public final class CreateAndDetectLoop { +public final class CreateAndDetectLoop { // Node class representing a single node in the linked list private CreateAndDetectLoop() { throw new UnsupportedOperationException("Utility class"); } - static final class Node { + static final class Node { int data; Node next; From 79fd8e3588a2b05b8b66a179a929575b0a360951 Mon Sep 17 00:00:00 2001 From: albinsabu2023 Date: Mon, 7 Oct 2024 11:03:17 +0530 Subject: [PATCH 7/9] all set --- .../datastructures/lists/CreateAndDetectLoop.java | 6 +----- .../datastructures/lists/CreateAndDetectLoopTest.java | 3 +-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java b/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java index d9c453694246..15c0502afd43 100644 --- a/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java +++ b/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java @@ -56,7 +56,6 @@ static void createLoop(Node head, int position1, int position2) { node2.next = node1; } } - // Method to detect a loop in the linked list /** * Detects the presence of a loop in the linked list. @@ -77,7 +76,4 @@ static boolean detectLoop(Node head) { } return false; } -} - - - +} \ No newline at end of file diff --git a/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java b/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java index 4b742e6818ff..455866df541d 100644 --- a/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java +++ b/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java @@ -68,5 +68,4 @@ void testCreateLoopNoChangeForNonExistentPositions() { // Ensure no loop was created assertFalse(CreateAndDetectLoop.detectLoop(head), "No loop should be created if positions are out of bounds."); } -} - +} \ No newline at end of file From 2d72ae4f428de98afa2a3dda3fcb3370269971ff Mon Sep 17 00:00:00 2001 From: albinsabu2023 Date: Mon, 7 Oct 2024 11:06:21 +0530 Subject: [PATCH 8/9] updated CreateAndDetectLoop with test --- .../thealgorithms/datastructures/lists/CreateAndDetectLoop.java | 1 + .../datastructures/lists/CreateAndDetectLoopTest.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java b/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java index 15c0502afd43..7c09d5befb8a 100644 --- a/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java +++ b/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java @@ -76,4 +76,5 @@ static boolean detectLoop(Node head) { } return false; } + } \ No newline at end of file diff --git a/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java b/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java index 455866df541d..c543b6f4e209 100644 --- a/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java +++ b/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java @@ -68,4 +68,5 @@ void testCreateLoopNoChangeForNonExistentPositions() { // Ensure no loop was created assertFalse(CreateAndDetectLoop.detectLoop(head), "No loop should be created if positions are out of bounds."); } + } \ No newline at end of file From 98cd2dad1688eeabc63bd0329c6d64bd54ec84d5 Mon Sep 17 00:00:00 2001 From: albinsabu2023 Date: Mon, 7 Oct 2024 11:08:42 +0530 Subject: [PATCH 9/9] updated createanddetectloop --- .../datastructures/lists/CreateAndDetectLoop.java | 3 +-- .../datastructures/lists/CreateAndDetectLoopTest.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java b/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java index 7c09d5befb8a..49115b2d0f3d 100644 --- a/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java +++ b/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java @@ -76,5 +76,4 @@ static boolean detectLoop(Node head) { } return false; } - -} \ No newline at end of file +} diff --git a/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java b/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java index c543b6f4e209..5e9d4c3a2913 100644 --- a/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java +++ b/src/test/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoopTest.java @@ -68,5 +68,4 @@ void testCreateLoopNoChangeForNonExistentPositions() { // Ensure no loop was created assertFalse(CreateAndDetectLoop.detectLoop(head), "No loop should be created if positions are out of bounds."); } - -} \ No newline at end of file +}