Repository: TheAlgorithms/Java
Pull request #6210 (2025-04-02 15:31:03)

refactor: introduce `SinglyLinkedListNode`
This is a step towards not suppressing `auxiliaryclass`:
https://github.com/TheAlgorithms/Java/blob/22098c7d1ef06df65ccfcd33bd17d8ad9783dafc/pom.xml#L78

This PR moves the `Node` class outside `SinglyLinkedList.java`.
The name `SinglyLinkedListNode` has the advantage that it is unique. I am open for suggestions here.

<!--
Thank you for your contribution!
In order to reduce the number of notifications sent to the maintainers, please:
- create your PR as draft, cf. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests#draft-pull-requests,
- make sure that all of the CI checks pass,
- mark your PR as ready for review, cf. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request#marking-a-pull-request-as-ready-for-review
-->

<!-- For completed items, change [ ] to [x] -->

- [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Java/blob/master/CONTRIBUTING.md).
- [x] This pull request is all my own work -- I have not plagiarized it.
- [x] All filenames are in PascalCase.
- [x] All functions and variable names follow Java naming conventions.
- [x] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
- [x] All new code is formatted with `clang-format -i --style=file path/to/your/file.java`

codecov-commenter: ## [Codecov](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6210?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) Report
Attention: Patch coverage is `92.00000%` with `4 lines` in your changes missing coverage. Please review.
> Project coverage is 73.77%. Comparing base [(`22098c7`)](https://app.codecov.io/gh/TheAlgorithms/Java/commit/22098c7d1ef06df65ccfcd33bd17d8ad9783dafc?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) to head [(`4e38765`)](https://app.codecov.io/gh/TheAlgorithms/Java/commit/4e3876500fa6ec9e3259f05f34f8f742ecd141e1?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms).

| [Files with missing lines](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6210?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) | Patch % | Lines |
|---|---|---|
| [...orithms/datastructures/lists/SinglyLinkedList.java](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6210?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Fcom%2Fthealgorithms%2Fdatastructures%2Flists%2FSinglyLinkedList.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms#diff-c3JjL21haW4vamF2YS9jb20vdGhlYWxnb3JpdGhtcy9kYXRhc3RydWN0dXJlcy9saXN0cy9TaW5nbHlMaW5rZWRMaXN0LmphdmE=) | 83.33% | [4 Missing :warning: ](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6210?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) |

<details><summary>Additional details and impacted files</summary>


```diff
@@             Coverage Diff              @@
##             master    #6210      +/-   ##
============================================
- Coverage     73.78%   73.77%   -0.01%     
- Complexity     5296     5299       +3     
============================================
  Files           670      671       +1     
  Lines         18343    18344       +1     
  Branches       3546     3546              
============================================
  Hits          13534    13534              
- Misses         4262     4263       +1     
  Partials        547      547              
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6210?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms).

<details><summary> :rocket: New features to boost your workflow: </summary>

- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>

Patch:
diff --git a/src/main/java/com/thealgorithms/datastructures/lists/CountSinglyLinkedListRecursion.java b/src/main/java/com/thealgorithms/datastructures/lists/CountSinglyLinkedListRecursion.java
index 4c1ffe9d..b58d51e7 100644
--- a/src/main/java/com/thealgorithms/datastructures/lists/CountSinglyLinkedListRecursion.java
+++ b/src/main/java/com/thealgorithms/datastructures/lists/CountSinglyLinkedListRecursion.java
@@ -12,7 +12,7 @@ public class CountSinglyLinkedListRecursion extends SinglyLinkedList {
      * @param head the head node of the list segment being counted.
      * @return the count of nodes from the given head node onward.
      */
-    private int countRecursion(Node head) {
+    private int countRecursion(SinglyLinkedListNode head) {
         return head == null ? 0 : 1 + countRecursion(head.next);
     }
 
diff --git a/src/main/java/com/thealgorithms/datastructures/lists/MergeSortedSinglyLinkedList.java b/src/main/java/com/thealgorithms/datastructures/lists/MergeSortedSinglyLinkedList.java
index a16b202c..4e99642f 100644
--- a/src/main/java/com/thealgorithms/datastructures/lists/MergeSortedSinglyLinkedList.java
+++ b/src/main/java/com/thealgorithms/datastructures/lists/MergeSortedSinglyLinkedList.java
@@ -42,12 +42,12 @@ public class MergeSortedSinglyLinkedList extends SinglyLinkedList {
             throw new NullPointerException("Input lists must not be null.");
         }
 
-        Node headA = listA.getHead();
-        Node headB = listB.getHead();
+        SinglyLinkedListNode headA = listA.getHead();
+        SinglyLinkedListNode headB = listB.getHead();
         int size = listA.size() + listB.size();
 
-        Node head = new Node();
-        Node tail = head;
+        SinglyLinkedListNode head = new SinglyLinkedListNode();
+        SinglyLinkedListNode tail = head;
         while (headA != null && headB != null) {
             if (headA.value <= headB.value) {
                 tail.next = headA;
diff --git a/src/main/java/com/thealgorithms/datastructures/lists/QuickSortLinkedList.java b/src/main/java/com/thealgorithms/datastructures/lists/QuickSortLinkedList.java
index 08fe674b..f018781a 100644
--- a/src/main/java/com/thealgorithms/datastructures/lists/QuickSortLinkedList.java
+++ b/src/main/java/com/thealgorithms/datastructures/lists/QuickSortLinkedList.java
@@ -105,7 +105,7 @@ package com.thealgorithms.datastructures.lists;
 public class QuickSortLinkedList {
 
     private final SinglyLinkedList list; // The linked list to be sorted
-    private Node head; // Head of the list
+    private SinglyLinkedListNode head; // Head of the list
 
     /**
      * Constructor that initializes the QuickSortLinkedList with a given linked list.
@@ -136,19 +136,19 @@ public class QuickSortLinkedList {
      * @param head The head node of the list to sort
      * @return The head node of the sorted linked list
      */
-    private Node sortList(Node head) {
+    private SinglyLinkedListNode sortList(SinglyLinkedListNode head) {
         if (head == null || head.next == null) {
             return head;
         }
 
-        Node pivot = head;
+        SinglyLinkedListNode pivot = head;
         head = head.next;
         pivot.next = null;
 
-        Node lessHead = new Node();
-        Node lessTail = lessHead;
-        Node greaterHead = new Node();
-        Node greaterTail = greaterHead;
+        SinglyLinkedListNode lessHead = new SinglyLinkedListNode();
+        SinglyLinkedListNode lessTail = lessHead;
+        SinglyLinkedListNode greaterHead = new SinglyLinkedListNode();
+        SinglyLinkedListNode greaterTail = greaterHead;
 
         while (head != null) {
             if (head.value < pivot.value) {
@@ -164,14 +164,14 @@ public class QuickSortLinkedList {
         lessTail.next = null;
         greaterTail.next = null;
 
-        Node sortedLess = sortList(lessHead.next);
-        Node sortedGreater = sortList(greaterHead.next);
+        SinglyLinkedListNode sortedLess = sortList(lessHead.next);
+        SinglyLinkedListNode sortedGreater = sortList(greaterHead.next);
 
         if (sortedLess == null) {
             pivot.next = sortedGreater;
             return pivot;
         } else {
-            Node current = sortedLess;
+            SinglyLinkedListNode current = sortedLess;
             while (current.next != null) {
                 current = current.next;
             }
diff --git a/src/main/java/com/thealgorithms/datastructures/lists/ReverseKGroup.java b/src/main/java/com/thealgorithms/datastructures/lists/ReverseKGroup.java
index c9a5c1df..9b9464d3 100644
--- a/src/main/java/com/thealgorithms/datastructures/lists/ReverseKGroup.java
+++ b/src/main/java/com/thealgorithms/datastructures/lists/ReverseKGroup.java
@@ -14,10 +14,10 @@ package com.thealgorithms.datastructures.lists;
  * </p>
  * <p>
  * The implementation contains:
- * - {@code length(Node head)}: A method to calculate the length of the linked list.
- * - {@code reverse(Node head, int count, int k)}: A helper method that reverses the nodes
+ * - {@code length(SinglyLinkedListNode head)}: A method to calculate the length of the linked list.
+ * - {@code reverse(SinglyLinkedListNode head, int count, int k)}: A helper method that reverses the nodes
  *   in the linked list in groups of k.
- * - {@code reverseKGroup(Node head, int k)}: The main method that initiates the reversal
+ * - {@code reverseKGroup(SinglyLinkedListNode head, int k)}: The main method that initiates the reversal
  *   process by calling the reverse method.
  * </p>
  * <p>
@@ -38,8 +38,8 @@ public class ReverseKGroup {
      * @param head The head node of the linked list.
      * @return The total number of nodes in the linked list.
      */
-    public int length(Node head) {
-        Node curr = head;
+    public int length(SinglyLinkedListNode head) {
+        SinglyLinkedListNode curr = head;
         int count = 0;
         while (curr != null) {
             curr = curr.next;
@@ -56,14 +56,14 @@ public class ReverseKGroup {
      * @param k The size of the group to reverse.
      * @return The new head of the reversed linked list segment.
      */
-    public Node reverse(Node head, int count, int k) {
+    public SinglyLinkedListNode reverse(SinglyLinkedListNode head, int count, int k) {
         if (count < k) {
             return head;
         }
-        Node prev = null;
+        SinglyLinkedListNode prev = null;
         int count1 = 0;
-        Node curr = head;
-        Node next = null;
+        SinglyLinkedListNode curr = head;
+        SinglyLinkedListNode next = null;
         while (curr != null && count1 < k) {
             next = curr.next;
             curr.next = prev;
@@ -85,7 +85,7 @@ public class ReverseKGroup {
      * @param k The size of the group to reverse.
      * @return The head of the modified linked list after reversal.
      */
-    public Node reverseKGroup(Node head, int k) {
+    public SinglyLinkedListNode reverseKGroup(SinglyLinkedListNode head, int k) {
         int count = length(head);
         return reverse(head, count, k);
     }
diff --git a/src/main/java/com/thealgorithms/datastructures/lists/RotateSinglyLinkedLists.java b/src/main/java/com/thealgorithms/datastructures/lists/RotateSinglyLinkedLists.java
index 7676cc34..47ee5397 100644
--- a/src/main/java/com/thealgorithms/datastructures/lists/RotateSinglyLinkedLists.java
+++ b/src/main/java/com/thealgorithms/datastructures/lists/RotateSinglyLinkedLists.java
@@ -38,12 +38,12 @@ public class RotateSinglyLinkedLists {
      * @param k The number of positions to rotate the list to the right.
      * @return The head of the rotated linked list.
      */
-    public Node rotateRight(Node head, int k) {
+    public SinglyLinkedListNode rotateRight(SinglyLinkedListNode head, int k) {
         if (head == null || head.next == null || k == 0) {
             return head;
         }
 
-        Node curr = head;
+        SinglyLinkedListNode curr = head;
         int len = 1;
         while (curr.next != null) {
             curr = curr.next;
diff --git a/src/main/java/com/thealgorithms/datastructures/lists/SearchSinglyLinkedListRecursion.java b/src/main/java/com/thealgorithms/datastructures/lists/SearchSinglyLinkedListRecursion.java
index a40e9b2a..4ac2de42 100644
--- a/src/main/java/com/thealgorithms/datastructures/lists/SearchSinglyLinkedListRecursion.java
+++ b/src/main/java/com/thealgorithms/datastructures/lists/SearchSinglyLinkedListRecursion.java
@@ -30,7 +30,7 @@ public class SearchSinglyLinkedListRecursion extends SinglyLinkedList {
      * @param key the integer value to be searched for.
      * @return {@code true} if the value `key` is present in the list; otherwise, {@code false}.
      */
-    private boolean searchRecursion(Node node, int key) {
+    private boolean searchRecursion(SinglyLinkedListNode node, int key) {
         return (node != null && (node.value == key || searchRecursion(node.next, key)));
     }
 
diff --git a/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java b/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java
index eb6cdf48..ff4af443 100644
--- a/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java
+++ b/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java
@@ -12,7 +12,7 @@ public class SinglyLinkedList implements Iterable<Integer> {
     /**
      * Head refer to the front of the list
      */
-    private Node head;
+    private SinglyLinkedListNode head;
 
     /**
      * Size of SinglyLinkedList
@@ -33,7 +33,7 @@ public class SinglyLinkedList implements Iterable<Integer> {
      * @param head the head node of list
      * @param size the size of list
      */
-    public SinglyLinkedList(Node head, int size) {
+    public SinglyLinkedList(SinglyLinkedListNode head, int size) {
         this.head = head;
         this.size = size;
     }
@@ -44,8 +44,8 @@ public class SinglyLinkedList implements Iterable<Integer> {
      *
      */
     public boolean detectLoop() {
-        Node currentNodeFast = head;
-        Node currentNodeSlow = head;
+        SinglyLinkedListNode currentNodeFast = head;
+        SinglyLinkedListNode currentNodeSlow = head;
         while (currentNodeFast != null && currentNodeFast.next != null) {
             currentNodeFast = currentNodeFast.next.next;
             currentNodeSlow = currentNodeSlow.next;
@@ -61,12 +61,12 @@ public class SinglyLinkedList implements Iterable<Integer> {
      * If the length of the list is even then return item number length/2
      * @return middle node of the list
      */
-    public Node middle() {
+    public SinglyLinkedListNode middle() {
         if (head == null) {
             return null;
         }
-        Node firstCounter = head;
-        Node secondCounter = firstCounter.next;
+        SinglyLinkedListNode firstCounter = head;
+        SinglyLinkedListNode secondCounter = firstCounter.next;
         while (secondCounter != null && secondCounter.next != null) {
             firstCounter = firstCounter.next;
             secondCounter = secondCounter.next.next;
@@ -82,15 +82,15 @@ public class SinglyLinkedList implements Iterable<Integer> {
         if (valueFirst == valueSecond) {
             return;
         }
-        Node previousA = null;
-        Node currentA = head;
+        SinglyLinkedListNode previousA = null;
+        SinglyLinkedListNode currentA = head;
         while (currentA != null && currentA.value != valueFirst) {
             previousA = currentA;
             currentA = currentA.next;
         }
 
-        Node previousB = null;
-        Node currentB = head;
+        SinglyLinkedListNode previousB = null;
+        SinglyLinkedListNode currentB = head;
         while (currentB != null && currentB.value != valueSecond) {
             previousB = currentB;
             currentB = currentB.next;
@@ -117,7 +117,7 @@ public class SinglyLinkedList implements Iterable<Integer> {
         }
         // Swap next pointer
 
-        Node temp = currentA.next;
+        var temp = currentA.next;
         currentA.next = currentB.next;
         currentB.next = temp;
     }
@@ -126,12 +126,12 @@ public class SinglyLinkedList implements Iterable<Integer> {
      * Reverse a singly linked list[Iterative] from a given node till the end
      *
      */
-    public Node reverseListIter(Node node) {
-        Node prev = null;
-        Node curr = node;
+    public SinglyLinkedListNode reverseListIter(SinglyLinkedListNode node) {
+        SinglyLinkedListNode prev = null;
+        SinglyLinkedListNode curr = node;
 
         while (curr != null && curr.next != null) {
-            Node next = curr.next;
+            var next = curr.next;
             curr.next = prev;
             prev = curr;
             curr = next;
@@ -149,13 +149,13 @@ public class SinglyLinkedList implements Iterable<Integer> {
      * Reverse a singly linked list[Recursive] from a given node till the end
      *
      */
-    public Node reverseListRec(Node head) {
+    public SinglyLinkedListNode reverseListRec(SinglyLinkedListNode head) {
         if (head == null || head.next == null) {
             return head;
         }
 
-        Node prev = null;
-        Node h2 = reverseListRec(head.next);
+        SinglyLinkedListNode prev = null;
+        SinglyLinkedListNode h2 = reverseListRec(head.next);
 
         head.next.next = head;
         head.next = prev;
@@ -167,7 +167,7 @@ public class SinglyLinkedList implements Iterable<Integer> {
      * Clear all nodes in the list
      */
     public void clear() {
-        Node cur = head;
+        SinglyLinkedListNode cur = head;
         while (cur != null) {
             cur = cur.next;
         }
@@ -198,7 +198,7 @@ public class SinglyLinkedList implements Iterable<Integer> {
      *
      * @return head of the list.
      */
-    public Node getHead() {
+    public SinglyLinkedListNode getHead() {
         return head;
     }
 
@@ -206,7 +206,7 @@ public class SinglyLinkedList implements Iterable<Integer> {
      * Set head of the list.
      *
      */
-    public void setHead(Node head) {
+    public void setHead(SinglyLinkedListNode head) {
         this.head = head;
     }
 
@@ -249,10 +249,10 @@ public class SinglyLinkedList implements Iterable<Integer> {
     }
 
     public void deleteDuplicates() {
-        Node pred = head;
+        SinglyLinkedListNode pred = head;
         // predecessor = the node
         // having sublist of its duplicates
-        Node newHead = head;
+        SinglyLinkedListNode newHead = head;
         while (newHead != null) {
             // if it's a beginning of duplicates sublist
             // skip all duplicates
@@ -273,7 +273,7 @@ public class SinglyLinkedList implements Iterable<Integer> {
     }
 
     public void print() {
-        Node temp = head;
+        SinglyLinkedListNode temp = head;
         while (temp != null && temp.next != null) {
             System.out.print(temp.value + "->");
             temp = temp.next;
@@ -310,7 +310,7 @@ public class SinglyLinkedList implements Iterable<Integer> {
      */
     public void insertNth(int data, int position) {
         checkBounds(position, 0, size);
-        Node newNode = new Node(data);
+        SinglyLinkedListNode newNode = new SinglyLinkedListNode(data);
         if (head == null) {
             /* the list is empty */
             head = newNode;
@@ -325,7 +325,7 @@ public class SinglyLinkedList implements Iterable<Integer> {
             return;
         }
 
-        Node cur = head;
+        SinglyLinkedListNode cur = head;
         for (int i = 0; i < position - 1; ++i) {
             cur = cur.next;
         }
@@ -359,7 +359,7 @@ public class SinglyLinkedList implements Iterable<Integer> {
             size--;
             return;
         }
-        Node cur = head;
+        SinglyLinkedListNode cur = head;
         for (int i = 0; i < position - 1; ++i) {
             cur = cur.next;
         }
@@ -376,7 +376,7 @@ public class SinglyLinkedList implements Iterable<Integer> {
      */
     public int getNth(int index) {
         checkBounds(index, 0, size - 1);
-        Node cur = head;
+        SinglyLinkedListNode cur = head;
         for (int i = 0; i < index; ++i) {
             cur = cur.next;
         }
@@ -440,7 +440,7 @@ public class SinglyLinkedList implements Iterable<Integer> {
         }
 
         SinglyLinkedList instance = new SinglyLinkedList();
-        Node head = new Node(0, new Node(2, new Node(3, new Node(3, new Node(4)))));
+        SinglyLinkedListNode head = new SinglyLinkedListNode(0, new SinglyLinkedListNode(2, new SinglyLinkedListNode(3, new SinglyLinkedListNode(3, new SinglyLinkedListNode(4)))));
         instance.setHead(head);
         instance.deleteDuplicates();
         instance.print();
@@ -452,7 +452,7 @@ public class SinglyLinkedList implements Iterable<Integer> {
     }
 
     private class SinglyLinkedListIterator implements Iterator<Integer> {
-        private Node current;
+        private SinglyLinkedListNode current;
 
         SinglyLinkedListIterator() {
             current = head;
@@ -474,43 +474,3 @@ public class SinglyLinkedList implements Iterable<Integer> {
         }
     }
 }
-
-/**
- * This class is the nodes of the SinglyLinked List. They consist of a value and
- * a pointer to the node after them.
- */
-class Node {
-
-    /**
-     * The value of the node
-     */
-    int value;
-
-    /**
-     * Point to the next node
-     */
-    Node next;
-
-    Node() {
-    }
-
-    /**
-     * Constructor
-     *
-     * @param value Value to be put in the node
-     */
-    Node(int value) {
-        this(value, null);
-    }
-
-    /**
-     * Constructor
-     *
-     * @param value Value to be put in the node
-     * @param next Reference to the next node
-     */
-    Node(int value, Node next) {
-        this.value = value;
-        this.next = next;
-    }
-}
diff --git a/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedListNode.java b/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedListNode.java
new file mode 100644
index 00000000..d0a06369
--- /dev/null
+++ b/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedListNode.java
@@ -0,0 +1,34 @@
+package com.thealgorithms.datastructures.lists;
+
+/**
+ * This class is the nodes of the SinglyLinked List. They consist of a value and
+ * a pointer to the node after them.
+ */
+class SinglyLinkedListNode {
+
+    int value;
+    SinglyLinkedListNode next = null;
+
+    SinglyLinkedListNode() {
+    }
+
+    /**
+     * Constructor
+     *
+     * @param value Value to be put in the node
+     */
+    SinglyLinkedListNode(int value) {
+        this(value, null);
+    }
+
+    /**
+     * Constructor
+     *
+     * @param value Value to be put in the node
+     * @param next Reference to the next node
+     */
+    SinglyLinkedListNode(int value, SinglyLinkedListNode next) {
+        this.value = value;
+        this.next = next;
+    }
+}


Test patch:
diff --git a/src/test/java/com/thealgorithms/datastructures/lists/ReverseKGroupTest.java b/src/test/java/com/thealgorithms/datastructures/lists/ReverseKGroupTest.java
index b2db478f..76b7ab06 100644
--- a/src/test/java/com/thealgorithms/datastructures/lists/ReverseKGroupTest.java
+++ b/src/test/java/com/thealgorithms/datastructures/lists/ReverseKGroupTest.java
@@ -20,8 +20,8 @@ public class ReverseKGroupTest {
     @Test
     public void testReverseKGroupWithSingleNodeList() {
         ReverseKGroup reverser = new ReverseKGroup();
-        Node singleNode = new Node(5);
-        Node result = reverser.reverseKGroup(singleNode, 2);
+        SinglyLinkedListNode singleNode = new SinglyLinkedListNode(5);
+        SinglyLinkedListNode result = reverser.reverseKGroup(singleNode, 2);
         assertEquals(5, result.value);
         assertNull(result.next);
     }
@@ -31,15 +31,15 @@ public class ReverseKGroupTest {
         ReverseKGroup reverser = new ReverseKGroup();
 
         // Create a list with multiple elements (1 -> 2 -> 3 -> 4 -> 5)
-        Node head;
-        head = new Node(1);
-        head.next = new Node(2);
-        head.next.next = new Node(3);
-        head.next.next.next = new Node(4);
-        head.next.next.next.next = new Node(5);
+        SinglyLinkedListNode head;
+        head = new SinglyLinkedListNode(1);
+        head.next = new SinglyLinkedListNode(2);
+        head.next.next = new SinglyLinkedListNode(3);
+        head.next.next.next = new SinglyLinkedListNode(4);
+        head.next.next.next.next = new SinglyLinkedListNode(5);
 
         // Test reverse with k=2
-        Node result1 = reverser.reverseKGroup(head, 2);
+        SinglyLinkedListNode result1 = reverser.reverseKGroup(head, 2);
         assertEquals(2, result1.value);
         assertEquals(1, result1.next.value);
         assertEquals(4, result1.next.next.value);
@@ -53,15 +53,15 @@ public class ReverseKGroupTest {
         ReverseKGroup reverser = new ReverseKGroup();
 
         // Create a list with multiple elements (1 -> 2 -> 3 -> 4 -> 5)
-        Node head;
-        head = new Node(1);
-        head.next = new Node(2);
-        head.next.next = new Node(3);
-        head.next.next.next = new Node(4);
-        head.next.next.next.next = new Node(5);
+        SinglyLinkedListNode head;
+        head = new SinglyLinkedListNode(1);
+        head.next = new SinglyLinkedListNode(2);
+        head.next.next = new SinglyLinkedListNode(3);
+        head.next.next.next = new SinglyLinkedListNode(4);
+        head.next.next.next.next = new SinglyLinkedListNode(5);
 
         // Test reverse with k=3
-        Node result = reverser.reverseKGroup(head, 3);
+        SinglyLinkedListNode result = reverser.reverseKGroup(head, 3);
         assertEquals(3, result.value);
         assertEquals(2, result.next.value);
         assertEquals(1, result.next.next.value);
diff --git a/src/test/java/com/thealgorithms/datastructures/lists/RotateSinglyLinkedListsTest.java b/src/test/java/com/thealgorithms/datastructures/lists/RotateSinglyLinkedListsTest.java
index 70c0dfcc..c476ad1b 100644
--- a/src/test/java/com/thealgorithms/datastructures/lists/RotateSinglyLinkedListsTest.java
+++ b/src/test/java/com/thealgorithms/datastructures/lists/RotateSinglyLinkedListsTest.java
@@ -14,24 +14,24 @@ public class RotateSinglyLinkedListsTest {
     private final RotateSinglyLinkedLists rotator = new RotateSinglyLinkedLists();
 
     // Helper method to create a linked list from an array of values
-    private Node createLinkedList(int[] values) {
+    private SinglyLinkedListNode createLinkedList(int[] values) {
         if (values.length == 0) {
             return null;
         }
 
-        Node head = new Node(values[0]);
-        Node current = head;
+        SinglyLinkedListNode head = new SinglyLinkedListNode(values[0]);
+        SinglyLinkedListNode current = head;
         for (int i = 1; i < values.length; i++) {
-            current.next = new Node(values[i]);
+            current.next = new SinglyLinkedListNode(values[i]);
             current = current.next;
         }
         return head;
     }
 
     // Helper method to convert a linked list to a string for easy comparison
-    private String linkedListToString(Node head) {
+    private String linkedListToString(SinglyLinkedListNode head) {
         StringBuilder sb = new StringBuilder();
-        Node current = head;
+        SinglyLinkedListNode current = head;
         while (current != null) {
             sb.append(current.value);
             if (current.next != null) {
@@ -51,55 +51,55 @@ public class RotateSinglyLinkedListsTest {
     @Test
     public void testRotateRightSingleNodeList() {
         // Rotate a list with a single element
-        Node singleNode = new Node(5);
-        Node rotatedSingleNode = rotator.rotateRight(singleNode, 3);
+        SinglyLinkedListNode singleNode = new SinglyLinkedListNode(5);
+        SinglyLinkedListNode rotatedSingleNode = rotator.rotateRight(singleNode, 3);
         assertEquals("5", linkedListToString(rotatedSingleNode));
     }
 
     @Test
     public void testRotateRightMultipleElementsList() {
         // Rotate a list with multiple elements (rotate by 2)
-        Node head = createLinkedList(new int[] {1, 2, 3, 4, 5});
-        Node rotated = rotator.rotateRight(head, 2);
+        SinglyLinkedListNode head = createLinkedList(new int[] {1, 2, 3, 4, 5});
+        SinglyLinkedListNode rotated = rotator.rotateRight(head, 2);
         assertEquals("4 -> 5 -> 1 -> 2 -> 3", linkedListToString(rotated));
     }
 
     @Test
     public void testRotateRightFullRotation() {
         // Rotate by more than the length of the list
-        Node head = createLinkedList(new int[] {1, 2, 3, 4, 5});
-        Node rotated = rotator.rotateRight(head, 7);
+        SinglyLinkedListNode head = createLinkedList(new int[] {1, 2, 3, 4, 5});
+        SinglyLinkedListNode rotated = rotator.rotateRight(head, 7);
         assertEquals("4 -> 5 -> 1 -> 2 -> 3", linkedListToString(rotated));
     }
 
     @Test
     public void testRotateRightZeroRotation() {
         // Rotate a list by k = 0 (no rotation)
-        Node head = createLinkedList(new int[] {1, 2, 3, 4, 5});
-        Node rotated = rotator.rotateRight(head, 0);
+        SinglyLinkedListNode head = createLinkedList(new int[] {1, 2, 3, 4, 5});
+        SinglyLinkedListNode rotated = rotator.rotateRight(head, 0);
         assertEquals("1 -> 2 -> 3 -> 4 -> 5", linkedListToString(rotated));
     }
 
     @Test
     public void testRotateRightByListLength() {
         // Rotate a list by k equal to list length (no change)
-        Node head = createLinkedList(new int[] {1, 2, 3, 4, 5});
-        Node rotated = rotator.rotateRight(head, 5);
+        SinglyLinkedListNode head = createLinkedList(new int[] {1, 2, 3, 4, 5});
+        SinglyLinkedListNode rotated = rotator.rotateRight(head, 5);
         assertEquals("1 -> 2 -> 3 -> 4 -> 5", linkedListToString(rotated));
     }
 
     @Test
     public void testRotateRightByMultipleOfListLength() {
-        Node head = createLinkedList(new int[] {1, 2, 3, 4, 5});
-        Node rotated = rotator.rotateRight(head, 10); // k = 2 * list length
+        SinglyLinkedListNode head = createLinkedList(new int[] {1, 2, 3, 4, 5});
+        SinglyLinkedListNode rotated = rotator.rotateRight(head, 10); // k = 2 * list length
         assertEquals("1 -> 2 -> 3 -> 4 -> 5", linkedListToString(rotated));
     }
 
     @Test
     public void testRotateRightLongerList() {
         // Rotate a longer list by a smaller k
-        Node head = createLinkedList(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9});
-        Node rotated = rotator.rotateRight(head, 4);
+        SinglyLinkedListNode head = createLinkedList(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9});
+        SinglyLinkedListNode rotated = rotator.rotateRight(head, 4);
         assertEquals("6 -> 7 -> 8 -> 9 -> 1 -> 2 -> 3 -> 4 -> 5", linkedListToString(rotated));
     }
 }
diff --git a/src/test/java/com/thealgorithms/datastructures/lists/SinglyLinkedListTest.java b/src/test/java/com/thealgorithms/datastructures/lists/SinglyLinkedListTest.java
index a4743408..f80c6b50 100644
--- a/src/test/java/com/thealgorithms/datastructures/lists/SinglyLinkedListTest.java
+++ b/src/test/java/com/thealgorithms/datastructures/lists/SinglyLinkedListTest.java
@@ -18,9 +18,9 @@ public class SinglyLinkedListTest {
      * @return linked list with pre-defined number of nodes
      */
     private SinglyLinkedList createSampleList(int length) {
-        List<Node> nodeList = new ArrayList<>();
+        List<SinglyLinkedListNode> nodeList = new ArrayList<>();
         for (int i = 1; i <= length; i++) {
-            Node node = new Node(i);
+            SinglyLinkedListNode node = new SinglyLinkedListNode(i);
             nodeList.add(node);
         }
 
@@ -34,10 +34,10 @@ public class SinglyLinkedListTest {
     @Test
     void detectLoop() {
         // List has cycle
-        Node firstNode = new Node(1);
-        Node secondNode = new Node(2);
-        Node thirdNode = new Node(3);
-        Node fourthNode = new Node(4);
+        SinglyLinkedListNode firstNode = new SinglyLinkedListNode(1);
+        SinglyLinkedListNode secondNode = new SinglyLinkedListNode(2);
+        SinglyLinkedListNode thirdNode = new SinglyLinkedListNode(3);
+        SinglyLinkedListNode fourthNode = new SinglyLinkedListNode(4);
 
         firstNode.next = secondNode;
         secondNode.next = thirdNode;
@@ -112,13 +112,13 @@ public class SinglyLinkedListTest {
 
         // Reversing the LinkedList using reverseList() method and storing the head of the reversed
         // linkedlist in a head node The reversed linkedlist will be 4->3->2->1->null
-        Node head = list.reverseListIter(list.getHead());
+        SinglyLinkedListNode head = list.reverseListIter(list.getHead());
 
         // Recording the Nodes after reversing the LinkedList
-        Node firstNode = head; // 4
-        Node secondNode = firstNode.next; // 3
-        Node thirdNode = secondNode.next; // 2
-        Node fourthNode = thirdNode.next; // 1
+        SinglyLinkedListNode firstNode = head; // 4
+        SinglyLinkedListNode secondNode = firstNode.next; // 3
+        SinglyLinkedListNode thirdNode = secondNode.next; // 2
+        SinglyLinkedListNode fourthNode = thirdNode.next; // 1
 
         // Checking whether the LinkedList is reversed or not by comparing the original list and
         // reversed list nodes
@@ -134,10 +134,10 @@ public class SinglyLinkedListTest {
     void reverseListNullPointer() {
         // Creating a linkedlist with first node assigned to null
         SinglyLinkedList list = new SinglyLinkedList();
-        Node first = list.getHead();
+        SinglyLinkedListNode first = list.getHead();
 
         // Reversing the linkedlist
-        Node head = list.reverseListIter(first);
+        SinglyLinkedListNode head = list.reverseListIter(first);
 
         // checking whether the method works fine if the input is null
         assertEquals(head, first);
@@ -151,10 +151,10 @@ public class SinglyLinkedListTest {
 
         // Reversing the LinkedList using reverseList() method and storing the head of the reversed
         // linkedlist in a head node
-        Node head = list.reverseListIter(list.getHead());
+        SinglyLinkedListNode head = list.reverseListIter(list.getHead());
 
         // Storing the head in a temp variable, so that we cannot loose the track of head
-        Node temp = head;
+        SinglyLinkedListNode temp = head;
 
         int i = 20; // This is for the comparison of values of nodes of the reversed linkedlist
         // Checking whether the reverseList() method performed its task
@@ -171,7 +171,7 @@ public class SinglyLinkedListTest {
         SinglyLinkedList list = createSampleList(5);
 
         // Reversing the linked list using reverseList() method
-        Node head = list.reverseListRec(list.getHead());
+        SinglyLinkedListNode head = list.reverseListRec(list.getHead());
 
         // Check if the reversed list is: 5 -> 4 -> 3 -> 2 -> 1
         assertEquals(5, head.value);
@@ -185,10 +185,10 @@ public class SinglyLinkedListTest {
     void recursiveReverseListNullPointer() {
         // Create an empty linked list
         SinglyLinkedList list = new SinglyLinkedList();
-        Node first = list.getHead();
+        SinglyLinkedListNode first = list.getHead();
 
         // Reversing the empty linked list
-        Node head = list.reverseListRec(first);
+        SinglyLinkedListNode head = list.reverseListRec(first);
 
         // Check if the head remains the same (null)
         assertNull(head);
@@ -200,11 +200,11 @@ public class SinglyLinkedListTest {
         SinglyLinkedList list = createSampleList(20);
 
         // Reversing the linked list using reverseList() method
-        Node head = list.reverseListRec(list.getHead());
+        SinglyLinkedListNode head = list.reverseListRec(list.getHead());
 
         // Check if the reversed list has the correct values
         int i = 20;
-        Node temp = head;
+        SinglyLinkedListNode temp = head;
         while (temp != null && i > 0) {
             assertEquals(i, temp.value);
             temp = temp.next;