Skip to content

Commit 51137a1

Browse files
refactor: review and group scattered palindrome implementation (#7487)
* feat: add utility to find lowest base for palindromic numbers and implement palindrome check for singly linked lists * feat: add palindrome check for linked lists and find lowest base palindrome implementation * feat: add utility to check if an integer's binary representation is a palindrome * feat: add algorithm to check if a singly linked list is a palindrome * feat: add PalindromeNumber utility class to check for palindromic integers * style: remove redundant import to fix checkstyle error * style: add blank line between static and non-static imports
1 parent 0e001b7 commit 51137a1

10 files changed

Lines changed: 61 additions & 7 deletions

File tree

src/main/java/com/thealgorithms/bitmanipulation/BinaryPalindromeCheck.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
* </p>
1010
*
1111
* @author Hardvan
12+
* @see com.thealgorithms.strings.Palindrome
13+
* @see com.thealgorithms.stacks.PalindromeWithStack
14+
* @see com.thealgorithms.maths.LowestBasePalindrome
15+
* @see com.thealgorithms.datastructures.lists.PalindromeSinglyLinkedList
16+
* @see com.thealgorithms.maths.PalindromePrime
17+
* @see com.thealgorithms.maths.PalindromeNumber
1218
*/
1319
public final class BinaryPalindromeCheck {
1420
private BinaryPalindromeCheck() {

src/main/java/com/thealgorithms/misc/PalindromeSinglyLinkedList.java renamed to src/main/java/com/thealgorithms/datastructures/lists/PalindromeSinglyLinkedList.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.thealgorithms.misc;
1+
package com.thealgorithms.datastructures.lists;
22

33
import java.util.Stack;
44

@@ -9,6 +9,13 @@
99
*
1010
* See more:
1111
* https://www.geeksforgeeks.org/function-to-check-if-a-singly-linked-list-is-palindrome/
12+
*
13+
* @see com.thealgorithms.strings.Palindrome
14+
* @see com.thealgorithms.stacks.PalindromeWithStack
15+
* @see com.thealgorithms.bitmanipulation.BinaryPalindromeCheck
16+
* @see com.thealgorithms.maths.LowestBasePalindrome
17+
* @see com.thealgorithms.maths.PalindromePrime
18+
* @see com.thealgorithms.maths.PalindromeNumber
1219
*/
1320
@SuppressWarnings("rawtypes")
1421
public final class PalindromeSinglyLinkedList {

src/main/java/com/thealgorithms/others/LowestBasePalindrome.java renamed to src/main/java/com/thealgorithms/maths/LowestBasePalindrome.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.thealgorithms.others;
1+
package com.thealgorithms.maths;
22

33
import java.util.ArrayList;
44
import java.util.List;
@@ -23,6 +23,12 @@
2323
*
2424
* @see <a href="https://oeis.org/A016026">OEIS A016026 - Smallest base in which
2525
* n is palindromic</a>
26+
* @see com.thealgorithms.strings.Palindrome
27+
* @see com.thealgorithms.stacks.PalindromeWithStack
28+
* @see com.thealgorithms.bitmanipulation.BinaryPalindromeCheck
29+
* @see com.thealgorithms.datastructures.lists.PalindromeSinglyLinkedList
30+
* @see com.thealgorithms.maths.PalindromePrime
31+
* @see com.thealgorithms.maths.PalindromeNumber
2632
* @author TheAlgorithms Contributors
2733
*/
2834
public final class LowestBasePalindrome {

src/main/java/com/thealgorithms/maths/PalindromeNumber.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
package com.thealgorithms.maths;
22

3+
/**
4+
* A class to check if a given number is a palindrome.
5+
* A palindromic number is a number that remains the same when its digits are reversed.
6+
*
7+
* @see com.thealgorithms.strings.Palindrome
8+
* @see com.thealgorithms.stacks.PalindromeWithStack
9+
* @see com.thealgorithms.bitmanipulation.BinaryPalindromeCheck
10+
* @see com.thealgorithms.maths.LowestBasePalindrome
11+
* @see com.thealgorithms.datastructures.lists.PalindromeSinglyLinkedList
12+
* @see com.thealgorithms.maths.PalindromePrime
13+
*/
314
public final class PalindromeNumber {
415
private PalindromeNumber() {
516
}

src/main/java/com/thealgorithms/misc/PalindromePrime.java renamed to src/main/java/com/thealgorithms/maths/PalindromePrime.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
package com.thealgorithms.misc;
1+
package com.thealgorithms.maths;
22

33
import java.util.ArrayList;
44
import java.util.List;
55

6+
/**
7+
* A class to check and generate palindromic prime numbers.
8+
* A palindromic prime is a prime number that is also a palindromic number.
9+
*
10+
* @see com.thealgorithms.strings.Palindrome
11+
* @see com.thealgorithms.stacks.PalindromeWithStack
12+
* @see com.thealgorithms.bitmanipulation.BinaryPalindromeCheck
13+
* @see com.thealgorithms.maths.LowestBasePalindrome
14+
* @see com.thealgorithms.datastructures.lists.PalindromeSinglyLinkedList
15+
* @see com.thealgorithms.maths.PalindromeNumber
16+
*/
617
public final class PalindromePrime {
718
private PalindromePrime() {
819
}

src/main/java/com/thealgorithms/stacks/PalindromeWithStack.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
* which we will pop one-by-one to create the string in reverse.
99
*
1010
* Reference: https://www.geeksforgeeks.org/check-whether-the-given-string-is-palindrome-using-stack/
11+
*
12+
* @see com.thealgorithms.strings.Palindrome
13+
* @see com.thealgorithms.bitmanipulation.BinaryPalindromeCheck
14+
* @see com.thealgorithms.maths.LowestBasePalindrome
15+
* @see com.thealgorithms.datastructures.lists.PalindromeSinglyLinkedList
16+
* @see com.thealgorithms.maths.PalindromePrime
17+
* @see com.thealgorithms.maths.PalindromeNumber
1118
*/
1219
public class PalindromeWithStack {
1320
private LinkedList<Character> stack;

src/main/java/com/thealgorithms/strings/Palindrome.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
/**
44
* Wikipedia: https://en.wikipedia.org/wiki/Palindrome
5+
*
6+
* @see com.thealgorithms.stacks.PalindromeWithStack
7+
* @see com.thealgorithms.bitmanipulation.BinaryPalindromeCheck
8+
* @see com.thealgorithms.maths.LowestBasePalindrome
9+
* @see com.thealgorithms.datastructures.lists.PalindromeSinglyLinkedList
10+
* @see com.thealgorithms.maths.PalindromePrime
11+
* @see com.thealgorithms.maths.PalindromeNumber
512
*/
613
final class Palindrome {
714
private Palindrome() {

src/test/java/com/thealgorithms/misc/PalindromeSinglyLinkedListTest.java renamed to src/test/java/com/thealgorithms/datastructures/lists/PalindromeSinglyLinkedListTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
package com.thealgorithms.misc;
1+
package com.thealgorithms.datastructures.lists;
22

33
import static org.junit.jupiter.api.Assertions.assertFalse;
44
import static org.junit.jupiter.api.Assertions.assertTrue;
55

6-
import com.thealgorithms.datastructures.lists.SinglyLinkedList;
76
import org.junit.jupiter.api.Test;
87

98
public class PalindromeSinglyLinkedListTest {

src/test/java/com/thealgorithms/others/LowestBasePalindromeTest.java renamed to src/test/java/com/thealgorithms/maths/LowestBasePalindromeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.thealgorithms.others;
1+
package com.thealgorithms.maths;
22

33
import java.util.ArrayList;
44
import java.util.Arrays;

src/test/java/com/thealgorithms/misc/PalindromePrimeTest.java renamed to src/test/java/com/thealgorithms/maths/PalindromePrimeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.thealgorithms.misc;
1+
package com.thealgorithms.maths;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertFalse;

0 commit comments

Comments
 (0)