From 192427a5d288b3b7d4eca28056ded28cac513b61 Mon Sep 17 00:00:00 2001 From: SOZEL <80200848+TruongNhanNguyen@users.noreply.github.com> Date: Sat, 16 Mar 2024 01:03:27 +0700 Subject: [PATCH] Parameterize references to generic types. (#5078) * chore: remove unused imports * fix: parameterize references to generic types --------- Co-authored-by: vil02 <65706193+vil02@users.noreply.github.com> --- src/main/java/com/thealgorithms/backtracking/MColoring.java | 1 - .../datastructures/dynamicarray/DynamicArray.java | 2 +- .../thealgorithms/datastructures/lists/CircleLinkedList.java | 4 ++-- .../thealgorithms/datastructures/lists/CursorLinkedList.java | 2 +- src/main/java/com/thealgorithms/misc/ThreeSumProblem.java | 4 ++-- src/main/java/com/thealgorithms/searches/UnionFind.java | 2 +- src/main/java/com/thealgorithms/strings/WordLadder.java | 4 ++-- 7 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/thealgorithms/backtracking/MColoring.java b/src/main/java/com/thealgorithms/backtracking/MColoring.java index c9bc02008058..93b17941566a 100644 --- a/src/main/java/com/thealgorithms/backtracking/MColoring.java +++ b/src/main/java/com/thealgorithms/backtracking/MColoring.java @@ -1,6 +1,5 @@ package com.thealgorithms.backtracking; -import java.io.*; import java.util.*; /** diff --git a/src/main/java/com/thealgorithms/datastructures/dynamicarray/DynamicArray.java b/src/main/java/com/thealgorithms/datastructures/dynamicarray/DynamicArray.java index fb7783575e57..f6f0276e0c35 100644 --- a/src/main/java/com/thealgorithms/datastructures/dynamicarray/DynamicArray.java +++ b/src/main/java/com/thealgorithms/datastructures/dynamicarray/DynamicArray.java @@ -145,7 +145,7 @@ public String toString() { * @return Iterator a Dynamic Array Iterator */ @Override - public Iterator iterator() { + public Iterator iterator() { return new DynamicArrayIterator(); } diff --git a/src/main/java/com/thealgorithms/datastructures/lists/CircleLinkedList.java b/src/main/java/com/thealgorithms/datastructures/lists/CircleLinkedList.java index 5d9f0b3a1d28..c42b10455d14 100644 --- a/src/main/java/com/thealgorithms/datastructures/lists/CircleLinkedList.java +++ b/src/main/java/com/thealgorithms/datastructures/lists/CircleLinkedList.java @@ -53,7 +53,7 @@ public void append(E value) { // utility function for traversing the list public String toString() { - Node p = head.next; + Node p = head.next; String s = "[ "; while (p != head) { s += p.value; @@ -91,7 +91,7 @@ public E remove(int pos) { } public static void main(String[] args) { - CircleLinkedList cl = new CircleLinkedList(); + CircleLinkedList cl = new CircleLinkedList<>(); cl.append(12); System.out.println(cl); cl.append(23); diff --git a/src/main/java/com/thealgorithms/datastructures/lists/CursorLinkedList.java b/src/main/java/com/thealgorithms/datastructures/lists/CursorLinkedList.java index cefc47c27169..22399bd6a459 100644 --- a/src/main/java/com/thealgorithms/datastructures/lists/CursorLinkedList.java +++ b/src/main/java/com/thealgorithms/datastructures/lists/CursorLinkedList.java @@ -134,7 +134,7 @@ public void remove(T element) { } private void free(int index) { - Node os_node = cursorSpace[os]; + Node os_node = cursorSpace[os]; int os_next = os_node.next; cursorSpace[os].next = index; cursorSpace[index].element = null; diff --git a/src/main/java/com/thealgorithms/misc/ThreeSumProblem.java b/src/main/java/com/thealgorithms/misc/ThreeSumProblem.java index 1b72996d022b..a232ad986970 100644 --- a/src/main/java/com/thealgorithms/misc/ThreeSumProblem.java +++ b/src/main/java/com/thealgorithms/misc/ThreeSumProblem.java @@ -75,7 +75,7 @@ public List> TwoPointer(int[] nums, int target) { public List> Hashmap(int[] nums, int target) { Arrays.sort(nums); - Set> ts = new HashSet(); + Set> ts = new HashSet<>(); HashMap hm = new HashMap<>(); for (int i = 0; i < nums.length; i++) { @@ -94,6 +94,6 @@ public List> Hashmap(int[] nums, int target) { } } } - return new ArrayList(ts); + return new ArrayList<>(ts); } } diff --git a/src/main/java/com/thealgorithms/searches/UnionFind.java b/src/main/java/com/thealgorithms/searches/UnionFind.java index d32e4fd3ec1f..4dfece0e6381 100644 --- a/src/main/java/com/thealgorithms/searches/UnionFind.java +++ b/src/main/java/com/thealgorithms/searches/UnionFind.java @@ -45,7 +45,7 @@ public void union(int x, int y) { } public int count() { - List parents = new ArrayList(); + List parents = new ArrayList<>(); for (int i = 0; i < p.length; i++) { if (!parents.contains(find(i))) { parents.add(find(i)); diff --git a/src/main/java/com/thealgorithms/strings/WordLadder.java b/src/main/java/com/thealgorithms/strings/WordLadder.java index a4634ce01ee0..e88acbd18586 100644 --- a/src/main/java/com/thealgorithms/strings/WordLadder.java +++ b/src/main/java/com/thealgorithms/strings/WordLadder.java @@ -51,13 +51,13 @@ class WordLadder { * if the endword is there. Otherwise, will return the length as 0. */ public static int ladderLength(String beginWord, String endWord, List wordList) { - HashSet set = new HashSet(wordList); + HashSet set = new HashSet<>(wordList); if (!set.contains(endWord)) { return 0; } - Queue queue = new LinkedList(); + Queue queue = new LinkedList<>(); queue.offer(beginWord); int level = 1;