From 0cab12688fd2841b97b1458a3fdf00b8f1b72a33 Mon Sep 17 00:00:00 2001 From: bcExpt1123 Date: Wed, 25 Jun 2025 17:08:52 +0100 Subject: [PATCH 01/22] Add Command Pattern to create an interactive menu system in Main.java --- src/main/java/org/alda/Main.java | 162 +++++++++++++++++- .../structure/linkedList/circular/Node.java | 2 +- .../alda/structure/linkedList/deque/Node.java | 2 +- .../linkedList/doubly/DoublyLinkedList.java | 1 - .../structure/linkedList/doubly/Node.java | 2 +- .../structure/linkedList/simple/Node.java | 2 +- .../linkedList/simple/SimpleLinkedList.java | 1 - 7 files changed, 159 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/alda/Main.java b/src/main/java/org/alda/Main.java index f9e7ba6..00fd008 100644 --- a/src/main/java/org/alda/Main.java +++ b/src/main/java/org/alda/Main.java @@ -24,40 +24,188 @@ import java.util.Arrays; import java.util.List; +import java.util.Scanner; +/** + * Main class demonstrating various data structures with an interactive menu. + */ public class Main { + private static final Scanner scanner = new Scanner(System.in); + public static void main(String[] args) { - testBST(); + boolean running = true; + + while (running) { + displayMainMenu(); + int choice = getMenuChoice(5); + + switch (choice) { + case 1 -> linkedListMenu(); + case 2 -> stackMenu(); + case 3 -> queueMenu(); + case 4 -> treeMenu(); + case 5 -> { + System.out.println("\nThank you for using Data Structure Demo!"); + running = false; + } + } + } + scanner.close(); + } + private static void displayMainMenu() { + System.out.println("\n=== Data Structure Demonstration ==="); + System.out.println("1. Linked Lists"); + System.out.println("2. Stacks"); + System.out.println("3. Queues"); + System.out.println("4. Trees"); + System.out.println("5. Exit"); + System.out.print("\nEnter your choice (1-5): "); + } + + private static void linkedListMenu() { + while (true) { + System.out.println("\n=== Linked List Types ==="); + System.out.println("1. Simple Linked List"); + System.out.println("2. Doubly Linked List"); + System.out.println("3. Circular Linked List"); + System.out.println("4. Sorted Linked List"); + System.out.println("5. Doubly Ended List (Deque)"); + System.out.println("6. Back to Main Menu"); + System.out.print("\nEnter your choice (1-6): "); + + int choice = getMenuChoice(6); + if (choice == 6) break; + + System.out.println("\n=== Test Results ==="); + switch (choice) { + case 1 -> testSimpleLinkedList(); + case 2 -> testDoublyLinkedList(); + case 3 -> testCircularLinkedList(); + case 4 -> testSortedLinkedList(); + case 5 -> testDoublyEndedList(); + } + pressEnterToContinue(); + } } + + private static void stackMenu() { + while (true) { + System.out.println("\n=== Stack Types ==="); + System.out.println("1. Array-based Stack"); + System.out.println("2. Linked List-based Stack"); + System.out.println("3. Back to Main Menu"); + System.out.print("\nEnter your choice (1-3): "); + + int choice = getMenuChoice(3); + if (choice == 3) break; + + System.out.println("\n=== Test Results ==="); + switch (choice) { + case 1 -> testStackArray(); + case 2 -> testStackLinkedList(); + } + pressEnterToContinue(); + } + } + + private static void queueMenu() { + while (true) { + System.out.println("\n=== Queue Types ==="); + System.out.println("1. Simple Queue"); + System.out.println("2. Array-based Queue"); + System.out.println("3. Linked List-based Queue"); + System.out.println("4. Priority Queue"); + System.out.println("5. Back to Main Menu"); + System.out.print("\nEnter your choice (1-5): "); + + int choice = getMenuChoice(5); + if (choice == 5) break; + + System.out.println("\n=== Test Results ==="); + switch (choice) { + case 1 -> testQueue(); + case 2 -> testQueueArray(); + case 3 -> testQueueLinkedList(); + case 4 -> testPriorityQueue(); + } + pressEnterToContinue(); + } + } + + private static void treeMenu() { + System.out.println("\n=== Tree Types ==="); + System.out.println("1. Binary Search Tree"); + System.out.println("2. AVL Tree"); + System.out.println("3. Back to Main Menu"); + System.out.print("\nEnter your choice (1-3): "); + + int choice = getMenuChoice(3); + if (choice == 3) return; + + System.out.println("\n=== Test Results ==="); + if (choice == 1) testBST(); + else if (choice == 2) testAVL(); + + pressEnterToContinue(); + } + + private static int getMenuChoice(int max) { + while (true) { + try { + int choice = Integer.parseInt(scanner.nextLine().trim()); + if (choice >= 1 && choice <= max) { + return choice; + } + System.out.printf("Please enter a number between 1 and %d: ", max); + } catch (NumberFormatException e) { + System.out.print("Invalid input. Please enter a number: "); + } + } + } + + private static void pressEnterToContinue() { + System.out.print("\nPress Enter to continue..."); + scanner.nextLine(); + } + public static void testSimpleLinkedList() { + System.out.println("\n=== Initialize Simple Linked List ==="); ISimpleLinkedList intList = new SimpleLinkedList(); + System.out.println("Actions: \n- Append 2, 3, 4, 5"); intList.append(2); intList.append(3); intList.append(4); intList.append(5); + System.out.println("- Insert after Head with 22"); intList.insertAfter(intList.getHead(), 22); + System.out.println("- Delete 3"); Node head = intList.delete(3); + System.out.print("\nPrint List:"); intList.print(); + System.out.print("\n\nHead:"); head.print(); - System.out.println(); - System.out.println(intList.search(2)); - System.out.println(intList.search(3)); - System.out.println(intList.search(4)); - System.out.println(intList.search(5)); + System.out.println("\n\nSearch for 2: " + intList.search(2)); + System.out.println("Search for 3: " + intList.search(3)); + System.out.println("Search for 4: " + intList.search(4)); + System.out.println("Search for 5: " + intList.search(5)); } public static void testDoublyLinkedList() { + System.out.println("\n=== Initialize Doubly Linked List ==="); DoublyLinkedList intList = new DoublyLinkedList(); + + System.out.println("Actions: \nAppend 2, 3, 4, 5"); intList.append(2); intList.append(3); intList.append(4); intList.append(5); - + + System.out.print("\nPrint List (Forward):"); intList.print(); } diff --git a/src/main/java/org/alda/structure/linkedList/circular/Node.java b/src/main/java/org/alda/structure/linkedList/circular/Node.java index f6f7cc6..90a38ad 100644 --- a/src/main/java/org/alda/structure/linkedList/circular/Node.java +++ b/src/main/java/org/alda/structure/linkedList/circular/Node.java @@ -53,7 +53,7 @@ public Node(T data) { * The output format is: {@code Data: , Next: } */ public void print() { - System.out.print("Data: " + data); + System.out.print("\nData: " + data); if (next != null) { System.out.print(", Next: " + next.data); } diff --git a/src/main/java/org/alda/structure/linkedList/deque/Node.java b/src/main/java/org/alda/structure/linkedList/deque/Node.java index 706c863..67671b7 100644 --- a/src/main/java/org/alda/structure/linkedList/deque/Node.java +++ b/src/main/java/org/alda/structure/linkedList/deque/Node.java @@ -56,7 +56,7 @@ public Node(){ * The output format is: {@code Data: , Next: , Prev: } */ public void print(){ - System.out.print("Data: " + data); + System.out.print("\nData: " + data); if (next != null) { System.out.print(", Next: " + next.data); } diff --git a/src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java b/src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java index a221db6..10f5e0e 100644 --- a/src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java +++ b/src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java @@ -85,7 +85,6 @@ public void print() { Node current = head; while (current != null) { current.print(); - System.out.println("\n"); current = current.next; } } diff --git a/src/main/java/org/alda/structure/linkedList/doubly/Node.java b/src/main/java/org/alda/structure/linkedList/doubly/Node.java index 3604b71..2042583 100644 --- a/src/main/java/org/alda/structure/linkedList/doubly/Node.java +++ b/src/main/java/org/alda/structure/linkedList/doubly/Node.java @@ -48,7 +48,7 @@ public Node(final T data) { * The output format is: {@code Data: , Next: , Prev: } */ public void print() { - System.out.print("Data: " + data); + System.out.print("\nData: " + data); if (next != null) { System.out.print(", Next: " + next.data); } diff --git a/src/main/java/org/alda/structure/linkedList/simple/Node.java b/src/main/java/org/alda/structure/linkedList/simple/Node.java index c654082..a2b1679 100644 --- a/src/main/java/org/alda/structure/linkedList/simple/Node.java +++ b/src/main/java/org/alda/structure/linkedList/simple/Node.java @@ -41,7 +41,7 @@ public Node(T data) { * The output format is: {@code Data: , Next: } */ public void print() { - System.out.print("Data: " + data); + System.out.print("\nData: " + data); if(next != null) { System.out.print(", Next: " + next.data); } diff --git a/src/main/java/org/alda/structure/linkedList/simple/SimpleLinkedList.java b/src/main/java/org/alda/structure/linkedList/simple/SimpleLinkedList.java index 6a37658..a670f29 100644 --- a/src/main/java/org/alda/structure/linkedList/simple/SimpleLinkedList.java +++ b/src/main/java/org/alda/structure/linkedList/simple/SimpleLinkedList.java @@ -142,7 +142,6 @@ public void print() { Node current = head; while (current != null) { current.print(); - System.out.println("\n"); current = current.next; } } From 9534874a8b9065a76afc01b0c4f05244b85a0c68 Mon Sep 17 00:00:00 2001 From: bcExpt1123 Date: Wed, 25 Jun 2025 17:31:34 +0100 Subject: [PATCH 02/22] Update test results --- src/main/java/org/alda/Main.java | 85 +++++++++++++------ .../circular/CircularLinkedList.java | 1 - .../linkedList/deque/DoublyEndedList.java | 1 - .../org/alda/structure/tree/bst/Node.java | 14 ++- 4 files changed, 72 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/alda/Main.java b/src/main/java/org/alda/Main.java index 00fd008..cafed5a 100644 --- a/src/main/java/org/alda/Main.java +++ b/src/main/java/org/alda/Main.java @@ -210,31 +210,39 @@ public static void testDoublyLinkedList() { } public static void testCircularLinkedList() { + System.out.println("\n=== Initialize Circular Linked List ==="); CircularLinkedList intList = new CircularLinkedList(); + System.out.println("Actions: \nAppend 2, 3, 4, 5"); intList.append(2); intList.append(3); intList.append(4); intList.append(5); + System.out.print("\nPrint List (Forward):"); intList.print(); } public static void testSortedLinkedList() { + System.out.println("\n=== Initialize Sorted Linked List ==="); ISortedLinkedList intList = new SortedLinkedList(); + System.out.println("Actions: \nSorted Insert 10, 50, 30, 70, 20"); intList.sortedInsert(10); intList.sortedInsert(50); intList.sortedInsert(30); intList.sortedInsert(70); intList.sortedInsert(20); + System.out.print("\nPrint List (Forward):"); intList.print(); } public static void testDoublyEndedList(){ + System.out.println("\n=== Initialize Doubly Ended Linked List ==="); IDoublyEndedList intList = new DoublyEndedList<>(); + System.out.println("Actions: \nAppend 1, 2, 3, 4, 5, 6, 7"); intList.appendEnd(1); intList.appendEnd(2); intList.appendFront(3); @@ -243,36 +251,43 @@ public static void testDoublyEndedList(){ intList.appendFront(6); intList.appendEnd(7); + System.out.print("\nPrint List (Forward):"); intList.print(); } public static void testStackArray(){ + System.out.println("\n=== Initialize Stack Array ==="); IStackArray intStack = new StackArray<>(); + System.out.println("Actions: \nPush 1, 2, 3"); intStack.push(1); intStack.push(2); intStack.push(3); - System.out.println(intStack.pop()); - System.out.println(intStack.peek()); - System.out.println(intStack.pop()); + System.out.println("\nPop: " + intStack.pop()); + System.out.println("Peek: " + intStack.peek()); + System.out.println("Pop: " + intStack.pop()); } public static void testStackLinkedList(){ + System.out.println("\n=== Initialize Stack Linked List ==="); IStackLinkedList intStack = new StackLinkedList<>(); + System.out.println("Actions: \nPush 1, 2, 3"); intStack.push(1); intStack.push(2); intStack.push(3); - System.out.println(intStack.pop()); - System.out.println(intStack.peek()); - System.out.println(intStack.pop()); + System.out.println("\nPop: " + intStack.pop()); + System.out.println("Peek: " + intStack.peek()); + System.out.println("Pop: " + intStack.pop()); } public static void testQueue(){ + System.out.println("\n=== Initialize Queue ==="); IQueue intQueue = new Queue<>(); + System.out.println("Actions: \nEnqueue 1, 2, 3, 4, 5"); intQueue.enqueue(1); intQueue.enqueue(2); intQueue.enqueue(3); @@ -286,16 +301,18 @@ public static void testQueue(){ Integer front = intQueue.front(); Integer rear = intQueue.rear(); - System.out.println(item); - System.out.println(item1); - System.out.println(item2); - System.out.println(front); - System.out.println(rear); + System.out.println("\nDequeue: " + item); + System.out.println("Dequeue: " + item1); + System.out.println("Dequeue: " + item2); + System.out.println("Front: " + front); + System.out.println("Rear: " + rear); } public static void testQueueArray(){ + System.out.println("\n=== Initialize Queue Array ==="); IQueue intQueue = new QueueArray<>(); + System.out.println("Actions: \nEnqueue 1, 2, 3, 4, 5"); intQueue.enqueue(1); intQueue.enqueue(2); intQueue.enqueue(3); @@ -309,16 +326,18 @@ public static void testQueueArray(){ Integer front = intQueue.front(); Integer rear = intQueue.rear(); - System.out.println(item); - System.out.println(item1); - System.out.println(item2); - System.out.println(front); - System.out.println(rear); + System.out.println("\nDequeue: " + item); + System.out.println("Dequeue: " + item1); + System.out.println("Dequeue: " + item2); + System.out.println("Front: " + front); + System.out.println("Rear: " + rear); } public static void testQueueLinkedList(){ + System.out.println("\n=== Initialize Queue Linked List ==="); IQueue intQueue = new QueueLinkedList<>(); + System.out.println("Actions: \nEnqueue 1, 2, 3, 4, 5"); intQueue.enqueue(1); intQueue.enqueue(2); intQueue.enqueue(3); @@ -332,21 +351,28 @@ public static void testQueueLinkedList(){ Integer front = intQueue.front(); Integer rear = intQueue.rear(); - System.out.println(item); - System.out.println(item1); - System.out.println(item2); - System.out.println(front); - System.out.println(rear); + System.out.println("\nDequeue: " + item); + System.out.println("Dequeue: " + item1); + System.out.println("Dequeue: " + item2); + System.out.println("Front: " + front); + System.out.println("Rear: " + rear); } public static void testPriorityQueue(){ + System.out.println("\n=== Initialize Priority Queue ==="); IPriorityQueue intQueue = new PriorityQueue<>(); + System.out.println("Actions: \n- Enqueue 2 with priority 1"); intQueue.enqueue(2, 1); + System.out.println("- Enqueue 32 with priority 25"); intQueue.enqueue(32, 25); + System.out.println("- Enqueue 48 with priority 0"); intQueue.enqueue(48, 0); + System.out.println("- Enqueue 15 with priority 3"); intQueue.enqueue(15, 3); + System.out.println("- Enqueue 36 with priority 2"); intQueue.enqueue(36, 2); + System.out.println("- Enqueue 27 with priority 4"); intQueue.enqueue(27, 4); Integer item = intQueue.dequeue(); @@ -354,14 +380,17 @@ public static void testPriorityQueue(){ Integer item2 = intQueue.dequeue(); Integer item3 = intQueue.dequeue(); - System.out.println(item); - System.out.println(item1); - System.out.println(item2); - System.out.println(item3); + System.out.println("\nDequeue: " + item); + System.out.println("Dequeue: " + item1); + System.out.println("Dequeue: " + item2); + System.out.println("Dequeue: " + item3); } public static void testBST(){ + System.out.println("\n=== Initialize Binary Search Tree ==="); BinarySearchTree bst = new BinarySearchTree<>(); + + System.out.println("Actions: \n- Insert 5, 3, 7, 1, 20, 4"); bst.insert(5); bst.insert(3); bst.insert(7); @@ -369,8 +398,12 @@ public static void testBST(){ bst.insert(20); bst.insert(4); + System.out.println("- Inorder Traversal "); System.out.println(bst.inorderTraversal()); - System.out.println(bst.search(4)); + System.out.print("\nSearch for 4: "); + org.alda.structure.tree.bst.Node node = bst.search(4); + if (node != null) System.out.println("true"); + else System.out.println("false"); } public static void testAVL(){ diff --git a/src/main/java/org/alda/structure/linkedList/circular/CircularLinkedList.java b/src/main/java/org/alda/structure/linkedList/circular/CircularLinkedList.java index 060ee78..acfdfd3 100644 --- a/src/main/java/org/alda/structure/linkedList/circular/CircularLinkedList.java +++ b/src/main/java/org/alda/structure/linkedList/circular/CircularLinkedList.java @@ -70,7 +70,6 @@ public void print() { Node current = head; while (current != null) { current.print(); - System.out.println("\n"); current = current.next; if(current == head) { break; diff --git a/src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java b/src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java index 12e69a4..c7107a5 100644 --- a/src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java +++ b/src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java @@ -75,7 +75,6 @@ public void print() { Node current = head; while (current != null) { current.print(); - System.out.println("\n"); current = current.next; } } diff --git a/src/main/java/org/alda/structure/tree/bst/Node.java b/src/main/java/org/alda/structure/tree/bst/Node.java index 5e2e701..fa1c82d 100644 --- a/src/main/java/org/alda/structure/tree/bst/Node.java +++ b/src/main/java/org/alda/structure/tree/bst/Node.java @@ -1,10 +1,12 @@ package org.alda.structure.tree.bst; +import org.alda.common.Printable; + /** * Node for binary search tree * @param */ -public class Node { +public class Node implements Printable { T key; Node left; Node right; @@ -13,4 +15,14 @@ public Node(T key){ left = null; right = null; } + + public void print() { + System.out.print("\nData: " + key); + if (left != null) { + System.out.print(", Left: " + left.key); + } + if (right != null) { + System.out.print(", Right: " + right.key); + } + } } From 7ac7f515980ea832cb037cd3008fbbff5e752868 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Wed, 25 Jun 2025 16:40:00 +0000 Subject: [PATCH 03/22] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`t?= =?UTF-8?q?est`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docstrings generation was requested by @bcExpt1123. * https://github.com/bcExpt1123/java-alda/pull/3#issuecomment-3005417343 The following files were modified: * `src/main/java/org/alda/Main.java` * `src/main/java/org/alda/structure/linkedList/circular/CircularLinkedList.java` * `src/main/java/org/alda/structure/linkedList/circular/Node.java` * `src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java` * `src/main/java/org/alda/structure/linkedList/deque/Node.java` * `src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java` * `src/main/java/org/alda/structure/linkedList/doubly/Node.java` * `src/main/java/org/alda/structure/linkedList/simple/Node.java` * `src/main/java/org/alda/structure/linkedList/simple/SimpleLinkedList.java` * `src/main/java/org/alda/structure/tree/bst/Node.java` --- src/main/java/org/alda/Main.java | 106 ++++++++++++++++++ .../circular/CircularLinkedList.java | 4 +- .../structure/linkedList/circular/Node.java | 5 +- .../linkedList/deque/DoublyEndedList.java | 3 +- .../alda/structure/linkedList/deque/Node.java | 6 +- .../linkedList/doubly/DoublyLinkedList.java | 3 +- .../structure/linkedList/doubly/Node.java | 7 +- .../structure/linkedList/simple/Node.java | 5 +- .../linkedList/simple/SimpleLinkedList.java | 2 +- .../org/alda/structure/tree/bst/Node.java | 10 ++ 10 files changed, 136 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/alda/Main.java b/src/main/java/org/alda/Main.java index cafed5a..2f93eb9 100644 --- a/src/main/java/org/alda/Main.java +++ b/src/main/java/org/alda/Main.java @@ -32,6 +32,13 @@ public class Main { private static final Scanner scanner = new Scanner(System.in); + /** + * Launches the interactive console application for demonstrating various data structures. + * + * Displays a main menu allowing users to select and explore different data structure categories, each with its own submenu and test demonstrations. The application continues running until the user chooses to exit. + * + * @param args command-line arguments (not used) + */ public static void main(String[] args) { boolean running = true; @@ -52,6 +59,9 @@ public static void main(String[] args) { } scanner.close(); } + /** + * Displays the main menu options for selecting a data structure category or exiting the program. + */ private static void displayMainMenu() { System.out.println("\n=== Data Structure Demonstration ==="); System.out.println("1. Linked Lists"); @@ -62,6 +72,11 @@ private static void displayMainMenu() { System.out.print("\nEnter your choice (1-5): "); } + /** + * Displays a submenu for selecting and testing different types of linked lists. + * + * Loops until the user chooses to return to the main menu. For each selection, runs the corresponding linked list demonstration and waits for user input before returning to the submenu. + */ private static void linkedListMenu() { while (true) { System.out.println("\n=== Linked List Types ==="); @@ -88,6 +103,11 @@ private static void linkedListMenu() { } } + /** + * Displays an interactive submenu for selecting and testing different stack implementations. + * + * Allows the user to choose between array-based and linked list-based stacks, runs the corresponding test demonstration, and returns to the main menu upon request. + */ private static void stackMenu() { while (true) { System.out.println("\n=== Stack Types ==="); @@ -108,6 +128,12 @@ private static void stackMenu() { } } + /** + * Displays an interactive submenu for selecting and testing different queue implementations. + * + * Presents options for simple queue, array-based queue, linked list-based queue, and priority queue. + * Executes the corresponding test method based on user selection and waits for user input before returning to the submenu. + */ private static void queueMenu() { while (true) { System.out.println("\n=== Queue Types ==="); @@ -132,6 +158,11 @@ private static void queueMenu() { } } + /** + * Displays a submenu for tree data structure demonstrations and runs the selected test. + * + * Presents options for Binary Search Tree and AVL Tree, executes the corresponding test method based on user input, and waits for user confirmation before returning. + */ private static void treeMenu() { System.out.println("\n=== Tree Types ==="); System.out.println("1. Binary Search Tree"); @@ -149,6 +180,12 @@ private static void treeMenu() { pressEnterToContinue(); } + /** + * Prompts the user to enter a menu choice and returns a valid integer within the specified range. + * + * @param max the maximum valid menu option (inclusive) + * @return the user's validated menu choice as an integer between 1 and {@code max} + */ private static int getMenuChoice(int max) { while (true) { try { @@ -163,11 +200,19 @@ private static int getMenuChoice(int max) { } } + /** + * Prompts the user to press Enter and waits for input before continuing. + */ private static void pressEnterToContinue() { System.out.print("\nPress Enter to continue..."); scanner.nextLine(); } + /** + * Demonstrates basic operations on a simple linked list of integers, including appending, inserting, deleting, printing, and searching for elements. + * + * Initializes a simple linked list, performs a sequence of modifications, prints the list and head node, and displays search results for specific values. + */ public static void testSimpleLinkedList() { System.out.println("\n=== Initialize Simple Linked List ==="); ISimpleLinkedList intList = new SimpleLinkedList(); @@ -195,6 +240,11 @@ public static void testSimpleLinkedList() { System.out.println("Search for 5: " + intList.search(5)); } + /** + * Demonstrates basic operations on a doubly linked list of integers. + * + * Initializes a doubly linked list, appends several integer values, and prints the list in forward order. + */ public static void testDoublyLinkedList() { System.out.println("\n=== Initialize Doubly Linked List ==="); DoublyLinkedList intList = new DoublyLinkedList(); @@ -209,6 +259,11 @@ public static void testDoublyLinkedList() { intList.print(); } + /** + * Demonstrates basic operations on a circular linked list of integers. + * + * Initializes a circular linked list, appends several integer values, and prints the list contents. + */ public static void testCircularLinkedList() { System.out.println("\n=== Initialize Circular Linked List ==="); CircularLinkedList intList = new CircularLinkedList(); @@ -223,6 +278,11 @@ public static void testCircularLinkedList() { intList.print(); } + /** + * Demonstrates the usage of a sorted linked list by inserting integers in non-sorted order and printing the sorted result. + * + * Initializes a sorted linked list, inserts several integer values using sorted insertion, and prints the list to show the maintained order. + */ public static void testSortedLinkedList() { System.out.println("\n=== Initialize Sorted Linked List ==="); ISortedLinkedList intList = new SortedLinkedList(); @@ -238,6 +298,11 @@ public static void testSortedLinkedList() { intList.print(); } + /** + * Demonstrates basic operations on a doubly ended linked list (deque) of integers. + * + * Initializes a doubly ended list, performs a sequence of insertions at both the front and end, and prints the resulting list. + */ public static void testDoublyEndedList(){ System.out.println("\n=== Initialize Doubly Ended Linked List ==="); IDoublyEndedList intList = new DoublyEndedList<>(); @@ -255,6 +320,11 @@ public static void testDoublyEndedList(){ intList.print(); } + /** + * Demonstrates basic operations on an array-based stack of integers. + * + * Initializes a stack, pushes several values, then performs pop and peek operations while printing the results. + */ public static void testStackArray(){ System.out.println("\n=== Initialize Stack Array ==="); IStackArray intStack = new StackArray<>(); @@ -269,6 +339,11 @@ public static void testStackArray(){ System.out.println("Pop: " + intStack.pop()); } + /** + * Demonstrates stack operations using a linked list implementation. + * + * Initializes a linked list-based stack, performs push, pop, and peek operations, and prints the results to the console. + */ public static void testStackLinkedList(){ System.out.println("\n=== Initialize Stack Linked List ==="); IStackLinkedList intStack = new StackLinkedList<>(); @@ -283,6 +358,11 @@ public static void testStackLinkedList(){ System.out.println("Pop: " + intStack.pop()); } + /** + * Demonstrates basic queue operations including enqueue, dequeue, and retrieving front and rear elements. + * + * Initializes a queue of integers, enqueues several values, dequeues three elements, and prints the results along with the current front and rear values. + */ public static void testQueue(){ System.out.println("\n=== Initialize Queue ==="); IQueue intQueue = new Queue<>(); @@ -308,6 +388,11 @@ public static void testQueue(){ System.out.println("Rear: " + rear); } + /** + * Demonstrates the usage of an array-based queue by performing enqueue, dequeue, and inspection operations. + * + * Initializes an integer queue, enqueues several elements, dequeues three elements, and prints the dequeued values along with the current front and rear elements. + */ public static void testQueueArray(){ System.out.println("\n=== Initialize Queue Array ==="); IQueue intQueue = new QueueArray<>(); @@ -333,6 +418,11 @@ public static void testQueueArray(){ System.out.println("Rear: " + rear); } + /** + * Demonstrates the usage of a linked list-based queue by performing enqueue, dequeue, and inspection operations. + * + * Initializes a queue, enqueues several integers, dequeues multiple elements, and prints the results along with the current front and rear elements. + */ public static void testQueueLinkedList(){ System.out.println("\n=== Initialize Queue Linked List ==="); IQueue intQueue = new QueueLinkedList<>(); @@ -358,6 +448,11 @@ public static void testQueueLinkedList(){ System.out.println("Rear: " + rear); } + /** + * Demonstrates the usage of a priority queue by enqueuing integer elements with specified priorities and dequeuing several elements to show priority-based removal order. + * + * This method initializes a priority queue, enqueues multiple integers with associated priorities, then dequeues and prints four elements to illustrate how the queue prioritizes elements. + */ public static void testPriorityQueue(){ System.out.println("\n=== Initialize Priority Queue ==="); IPriorityQueue intQueue = new PriorityQueue<>(); @@ -386,6 +481,12 @@ public static void testPriorityQueue(){ System.out.println("Dequeue: " + item3); } + /** + * Demonstrates basic operations on a binary search tree, including insertion, inorder traversal, and search. + * + * Initializes a binary search tree of integers, inserts several values, prints the inorder traversal, + * and searches for the value 4, displaying whether it is found. + */ public static void testBST(){ System.out.println("\n=== Initialize Binary Search Tree ==="); BinarySearchTree bst = new BinarySearchTree<>(); @@ -406,6 +507,11 @@ public static void testBST(){ else System.out.println("false"); } + /** + * Demonstrates insertion of multiple integers into an AVL tree. + * + * Initializes an AVL tree and inserts the values 10, 20, 30, 40, 50, and 25 to showcase automatic balancing during insertion. + */ public static void testAVL(){ AVL avl = new AVL<>(); AVL.Node root = null; diff --git a/src/main/java/org/alda/structure/linkedList/circular/CircularLinkedList.java b/src/main/java/org/alda/structure/linkedList/circular/CircularLinkedList.java index acfdfd3..059bf43 100644 --- a/src/main/java/org/alda/structure/linkedList/circular/CircularLinkedList.java +++ b/src/main/java/org/alda/structure/linkedList/circular/CircularLinkedList.java @@ -63,8 +63,8 @@ public void append(T data) { } /** - * Prints the data stored in each node of the circular linked list. - * The traversal stops when the list has looped back to the head. + * Prints the data of each node in the circular linked list in sequence, starting from the head. + * Traversal continues until the list loops back to the head node or if the list is empty. */ public void print() { Node current = head; diff --git a/src/main/java/org/alda/structure/linkedList/circular/Node.java b/src/main/java/org/alda/structure/linkedList/circular/Node.java index 90a38ad..7d38727 100644 --- a/src/main/java/org/alda/structure/linkedList/circular/Node.java +++ b/src/main/java/org/alda/structure/linkedList/circular/Node.java @@ -49,8 +49,9 @@ public Node(T data) { } /** - * Prints the data stored in this node and, if present, the data in the next node. - * The output format is: {@code Data: , Next: } + * Prints this node's data and, if available, the data of the next node to standard output. + * + * The output begins with a newline and follows the format: {@code Data: , Next: }. */ public void print() { System.out.print("\nData: " + data); diff --git a/src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java b/src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java index c7107a5..139206a 100644 --- a/src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java +++ b/src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java @@ -68,8 +68,7 @@ public void setTail(Node tail) { } /** - * Prints the contents of the list. - * Each node's data is printed, followed by a new line. + * Prints the data of each node in the list from head to tail. */ public void print() { Node current = head; diff --git a/src/main/java/org/alda/structure/linkedList/deque/Node.java b/src/main/java/org/alda/structure/linkedList/deque/Node.java index 67671b7..15dd1f9 100644 --- a/src/main/java/org/alda/structure/linkedList/deque/Node.java +++ b/src/main/java/org/alda/structure/linkedList/deque/Node.java @@ -52,8 +52,10 @@ public Node(){ } /** - * Prints the data stored in this node, and if present, the data in the next and previous nodes. - * The output format is: {@code Data: , Next: , Prev: } + * Prints this node's data, along with the data of adjacent nodes if available, to standard output. + * + * The output includes the node's data, and, if present, the data of the next and previous nodes in the format: + * {@code Data: , Next: , Prev: }. */ public void print(){ System.out.print("\nData: " + data); diff --git a/src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java b/src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java index 10f5e0e..5dcc123 100644 --- a/src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java +++ b/src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java @@ -78,8 +78,7 @@ public void prepend(T data) { } /** - * Prints the data stored in each node of the doubly linked list from head to tail. - * Each node's data is printed along with the data in its next and previous nodes, if available. + * Prints each node's data in the list from head to tail, including adjacent nodes' data if present. */ public void print() { Node current = head; diff --git a/src/main/java/org/alda/structure/linkedList/doubly/Node.java b/src/main/java/org/alda/structure/linkedList/doubly/Node.java index 2042583..31d793b 100644 --- a/src/main/java/org/alda/structure/linkedList/doubly/Node.java +++ b/src/main/java/org/alda/structure/linkedList/doubly/Node.java @@ -44,8 +44,11 @@ public Node(final T data) { } /** - * Prints the data stored in this node, as well as the data in the next and previous nodes, if available. - * The output format is: {@code Data: , Next: , Prev: } + * Prints this node's data, along with the data of adjacent nodes if they exist. + * + * The output begins with a newline and follows the format: + * {@code Data: , Next: , Prev: }. + * The "Next" and "Prev" fields are included only if the corresponding nodes are present. */ public void print() { System.out.print("\nData: " + data); diff --git a/src/main/java/org/alda/structure/linkedList/simple/Node.java b/src/main/java/org/alda/structure/linkedList/simple/Node.java index a2b1679..ef67119 100644 --- a/src/main/java/org/alda/structure/linkedList/simple/Node.java +++ b/src/main/java/org/alda/structure/linkedList/simple/Node.java @@ -37,8 +37,9 @@ public Node(T data) { } /** - * Prints the data stored in this node and, if present, the data in the next node. - * The output format is: {@code Data: , Next: } + * Prints the data of this node, and if a next node exists, also prints its data. + * + * The output is formatted as: {@code Data: , Next: }, with a preceding newline. */ public void print() { System.out.print("\nData: " + data); diff --git a/src/main/java/org/alda/structure/linkedList/simple/SimpleLinkedList.java b/src/main/java/org/alda/structure/linkedList/simple/SimpleLinkedList.java index a670f29..a430fa5 100644 --- a/src/main/java/org/alda/structure/linkedList/simple/SimpleLinkedList.java +++ b/src/main/java/org/alda/structure/linkedList/simple/SimpleLinkedList.java @@ -136,7 +136,7 @@ public void setHead(Node head) { } /** - * Prints the data stored in each node of the linked list from head to tail. + * Outputs the data of each node in the linked list sequentially from head to tail. */ public void print() { Node current = head; diff --git a/src/main/java/org/alda/structure/tree/bst/Node.java b/src/main/java/org/alda/structure/tree/bst/Node.java index fa1c82d..80dfd71 100644 --- a/src/main/java/org/alda/structure/tree/bst/Node.java +++ b/src/main/java/org/alda/structure/tree/bst/Node.java @@ -10,12 +10,22 @@ public class Node implements Printable { T key; Node left; Node right; + /** + * Constructs a new node with the specified key and no child nodes. + * + * @param key the value to store in this node + */ public Node(T key){ this.key = key; left = null; right = null; } + /** + * Prints the node's key and the keys of its left and right children, if present, to the standard output. + * + * The output format is: "Data: [key], Left: [left.key], Right: [right.key]". Child information is omitted if the respective child is null. + */ public void print() { System.out.print("\nData: " + key); if (left != null) { From 38b610302a1a5d08949a5e0a5d7d18f24d3a008f Mon Sep 17 00:00:00 2001 From: bcExpt1123 Date: Thu, 26 Jun 2025 10:09:23 +0100 Subject: [PATCH 04/22] Add AVL tests --- src/main/java/org/alda/Main.java | 8 +-- src/main/java/org/alda/common/Utils.java | 16 ++++++ .../org/alda/structure/tree/bst/bbt/AVL.java | 8 +-- .../alda/structure/tree/bst/bbt/AVLTest.java | 50 +++++++++++++++++++ src/test/java/org/alda/common/UtilsTest.java | 42 ++++++++++++++++ 5 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/alda/common/Utils.java create mode 100644 src/main/java/org/alda/structure/tree/bst/bbt/AVLTest.java create mode 100644 src/test/java/org/alda/common/UtilsTest.java diff --git a/src/main/java/org/alda/Main.java b/src/main/java/org/alda/Main.java index cafed5a..3e58d78 100644 --- a/src/main/java/org/alda/Main.java +++ b/src/main/java/org/alda/Main.java @@ -21,6 +21,7 @@ import org.alda.structure.stack.linkedList.StackLinkedList; import org.alda.structure.tree.bst.BinarySearchTree; import org.alda.structure.tree.bst.bbt.AVL; +import org.alda.structure.tree.bst.bbt.AVLTest; import java.util.Arrays; import java.util.List; @@ -407,11 +408,6 @@ public static void testBST(){ } public static void testAVL(){ - AVL avl = new AVL<>(); - AVL.Node root = null; - List keys = Arrays.asList(10, 20, 30, 40, 50, 25); - for(Integer key : keys){ - avl.insert(root, key); - } + AVLTest.main(null); } } \ No newline at end of file diff --git a/src/main/java/org/alda/common/Utils.java b/src/main/java/org/alda/common/Utils.java new file mode 100644 index 0000000..3b4bf7e --- /dev/null +++ b/src/main/java/org/alda/common/Utils.java @@ -0,0 +1,16 @@ +package org.alda.common; + +import java.util.Arrays; + +public class Utils { + public static String intArrToStr(int[] arr, String delimiter) { + return Arrays.stream(arr) + .mapToObj(String::valueOf) + .reduce((a, b) -> a + delimiter + b) + .orElse(""); + } + + public static String intArrToStr(int[] arr) { + return intArrToStr(arr, ", "); + } +} diff --git a/src/main/java/org/alda/structure/tree/bst/bbt/AVL.java b/src/main/java/org/alda/structure/tree/bst/bbt/AVL.java index 8df37c9..a9db4da 100644 --- a/src/main/java/org/alda/structure/tree/bst/bbt/AVL.java +++ b/src/main/java/org/alda/structure/tree/bst/bbt/AVL.java @@ -43,8 +43,10 @@ public Node insert(Node root, T key) { return new Node<>(key); } else if (key.compareTo(root.key) < 0) { root.left = insert(root.left, key); - } else { + } else if (key.compareTo(root.key) > 0) { root.right = insert(root.right, key); + } else { + return root; // Duplicate keys not allowed } root.height = 1 + Math.max(getHeight(root.left), getHeight(root.right)); @@ -73,8 +75,8 @@ public Integer getHeight(Node root) { } public Integer getBalance(Node root) { - if(root == null) return 0; - return getHeight(root.left) + getHeight(root.right); + if (root == null) return 0; + return getHeight(root.left) - getHeight(root.right); } public Node rotateRight(Node z) { diff --git a/src/main/java/org/alda/structure/tree/bst/bbt/AVLTest.java b/src/main/java/org/alda/structure/tree/bst/bbt/AVLTest.java new file mode 100644 index 0000000..01e082d --- /dev/null +++ b/src/main/java/org/alda/structure/tree/bst/bbt/AVLTest.java @@ -0,0 +1,50 @@ +package org.alda.structure.tree.bst.bbt; + +import org.alda.common.Utils; + +public class AVLTest { + public static void main(String[] args) { + System.out.println("\n=== Initialize AVL Tree ==="); + AVL avl = new AVL<>(); + AVL.Node root = null; + + // Insert elements to test rotations + int[] elements = {10, 20, 30, 40, 50, 25}; + + System.out.println("Actions: \n- Insert " + Utils.intArrToStr(elements)); + for (int el : elements) { + root = avl.insert(root, el); + } + + // Print tree in in-order + System.out.println("\nIn-order traversal:"); + inOrder(root); + + // Print tree structure + System.out.println("\n\nTree structure:"); + printTree(root, "", true); + } + + // In-order traversal (left-root-right) + public static > void inOrder(AVL.Node node) { + if (node != null) { + inOrder(node.left); + System.out.print(node.key + " "); + inOrder(node.right); + } + } + + // Pretty-print the tree + public static > void printTree(AVL.Node node, String prefix, boolean isTail) { + if (node == null) return; + + System.out.println(prefix + (isTail ? "└── " : "├── ") + node.key + " (h=" + node.height + ")"); + + if (node.left != null || node.right != null) { + if (node.right != null) + printTree(node.right, prefix + (isTail ? " " : "│ "), node.left == null); + if (node.left != null) + printTree(node.left, prefix + (isTail ? " " : "│ "), true); + } + } +} diff --git a/src/test/java/org/alda/common/UtilsTest.java b/src/test/java/org/alda/common/UtilsTest.java new file mode 100644 index 0000000..b0a07f7 --- /dev/null +++ b/src/test/java/org/alda/common/UtilsTest.java @@ -0,0 +1,42 @@ +package org.alda.common; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class UtilsTest { + @Test + void testNormalArray() { + int[] arr = {1, 2, 3, 4, 5}; + String result = Utils.intArrToStr(arr, ","); + assertEquals("1,2,3,4,5", result); + } + + @Test + void testSingleElementArray() { + int[] arr = {42}; + String result = Utils.intArrToStr(arr, ","); + assertEquals("42", result); + } + + @Test + void testEmptyArray() { + int[] arr = {}; + String result = Utils.intArrToStr(arr, ","); + assertEquals("", result); + } + + @Test + void testDifferentDelimiter() { + int[] arr = {10, 20, 30}; + String result = Utils.intArrToStr(arr, " | "); + assertEquals("10 | 20 | 30", result); + } + + @Test + void testNegativeNumbers() { + int[] arr = {-1, -2, -3}; + String result = Utils.intArrToStr(arr, ";"); + assertEquals("-1;-2;-3", result); + } +} From ce419034c7506730ba34c81d0634fa017dbdea55 Mon Sep 17 00:00:00 2001 From: bcExpt1123 Date: Thu, 26 Jun 2025 10:28:18 +0100 Subject: [PATCH 05/22] Add Style checker --- README.md | 8 ++++++++ checkstyle.xml | 21 +++++++++++++++++++++ pom.xml | 24 +++++++++++++++++++++++- src/main/java/org/alda/Main.java | 3 --- 4 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 checkstyle.xml diff --git a/README.md b/README.md index d9c919a..304c0fa 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,14 @@ Run test: ```sh mvn test ``` +Run Check style: +```sh + mvn checkstyle:check +``` +Or +```sh + mvn checkstyle:checkstyle +``` ## Contributing diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 0000000..d41ff10 --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 8a76594..f73fdbb 100644 --- a/pom.xml +++ b/pom.xml @@ -28,5 +28,27 @@ test - + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.3.0 + + + verify + + check + + + + + checkstyle.xml + UTF-8 + true + true + + + + \ No newline at end of file diff --git a/src/main/java/org/alda/Main.java b/src/main/java/org/alda/Main.java index baf49fb..7b9f468 100644 --- a/src/main/java/org/alda/Main.java +++ b/src/main/java/org/alda/Main.java @@ -20,11 +20,8 @@ import org.alda.structure.stack.linkedList.IStackLinkedList; import org.alda.structure.stack.linkedList.StackLinkedList; import org.alda.structure.tree.bst.BinarySearchTree; -import org.alda.structure.tree.bst.bbt.AVL; import org.alda.structure.tree.bst.bbt.AVLTest; -import java.util.Arrays; -import java.util.List; import java.util.Scanner; /** From bc46e24780bc4e7c79590c6abb48d3c609218e76 Mon Sep 17 00:00:00 2001 From: Magni - God of Strength Date: Thu, 26 Jun 2025 05:43:23 -0400 Subject: [PATCH 06/22] Create summarize_new_issue.yaml --- .github/workflows/summarize_new_issue.yaml | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/summarize_new_issue.yaml diff --git a/.github/workflows/summarize_new_issue.yaml b/.github/workflows/summarize_new_issue.yaml new file mode 100644 index 0000000..9b07bb8 --- /dev/null +++ b/.github/workflows/summarize_new_issue.yaml @@ -0,0 +1,34 @@ +name: Summarize new issues + +on: + issues: + types: [opened] + +jobs: + summary: + runs-on: ubuntu-latest + permissions: + issues: write + models: read + contents: read + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Run AI inference + id: inference + uses: actions/ai-inference@v1 + with: + prompt: | + Summarize the following GitHub issue in one paragraph: + Title: ${{ github.event.issue.title }} + Body: ${{ github.event.issue.body }} + + - name: Comment with AI summary + run: | + gh issue comment $ISSUE_NUMBER --body '${{ steps.inference.outputs.response }}' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ISSUE_NUMBER: ${{ github.event.issue.number }} + RESPONSE: ${{ steps.inference.outputs.response }} From b112a6b41fb16ca7426ca7ef73f2905c6331fa9c Mon Sep 17 00:00:00 2001 From: Magni - God of Strength Date: Thu, 26 Jun 2025 05:47:53 -0400 Subject: [PATCH 07/22] Create label_pr.yaml --- .github/workflows/label_pr.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/label_pr.yaml diff --git a/.github/workflows/label_pr.yaml b/.github/workflows/label_pr.yaml new file mode 100644 index 0000000..4613569 --- /dev/null +++ b/.github/workflows/label_pr.yaml @@ -0,0 +1,22 @@ +# This workflow will triage pull requests and apply a label based on the +# paths that are modified in the pull request. +# +# To use this workflow, you will need to set up a .github/labeler.yml +# file with configuration. For more information, see: +# https://github.com/actions/labeler + +name: Labeler +on: [pull_request_target] + +jobs: + label: + + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + + steps: + - uses: actions/labeler@v4 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" From 00b8e62e30ea0f2f0bf4aa4ae212978d1d5dcee9 Mon Sep 17 00:00:00 2001 From: Magni - God of Strength Date: Thu, 26 Jun 2025 05:49:48 -0400 Subject: [PATCH 08/22] Create maven.yaml --- .github/workflows/maven.yaml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/maven.yaml diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml new file mode 100644 index 0000000..06b6aa0 --- /dev/null +++ b/.github/workflows/maven.yaml @@ -0,0 +1,35 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn -B package --file pom.xml + + # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive + - name: Update dependency graph + uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 From d4386b738ffe3c0f757c4ce10959705f6d5ab261 Mon Sep 17 00:00:00 2001 From: Magni - God of Strength Date: Thu, 26 Jun 2025 05:52:26 -0400 Subject: [PATCH 09/22] Create pmd.yaml --- .github/workflows/pmd.yaml | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/pmd.yaml diff --git a/.github/workflows/pmd.yaml b/.github/workflows/pmd.yaml new file mode 100644 index 0000000..310b100 --- /dev/null +++ b/.github/workflows/pmd.yaml @@ -0,0 +1,41 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: pmd + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + pmd-code-scan: + permissions: + contents: read # for actions/checkout to fetch code + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results + actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + java-version: '11' + distribution: 'temurin' + - name: Run PMD + id: pmd + uses: pmd/pmd-github-action@967a81f8b657c87f7c3e96b62301cb1a48efef29 + with: + rulesets: 'rulesets/java/quickstart.xml' + sourcePath: 'src/main/java' + analyzeModifiedFilesOnly: false + - name: Upload SARIF file + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: pmd-report.sarif From 6cd75ef7644bb96bc9c8cb024cfa0e802ece54bd Mon Sep 17 00:00:00 2001 From: Magni - God of Strength Date: Thu, 26 Jun 2025 05:55:39 -0400 Subject: [PATCH 10/22] Create codeql --- .github/workflows/codeql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/codeql diff --git a/.github/workflows/codeql b/.github/workflows/codeql new file mode 100644 index 0000000..7a82612 --- /dev/null +++ b/.github/workflows/codeql @@ -0,0 +1,14 @@ +name: CodeQL analysis + +on: + push: + branches: [main] + pull_request: + branches: [main] + schedule: + - cron: '0 3 * * 0' + +jobs: + call-codeQL-analysis: + name: CodeQL analysis + uses: actions/reusable-workflows/.github/workflows/codeql-analysis.yml@main From 3f456f5931b7dd56fbd2234de1d2a636fb5bd0fa Mon Sep 17 00:00:00 2001 From: Magni - God of Strength Date: Thu, 26 Jun 2025 05:56:02 -0400 Subject: [PATCH 11/22] Rename codeql to codeql.yaml --- .github/workflows/{codeql => codeql.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{codeql => codeql.yaml} (100%) diff --git a/.github/workflows/codeql b/.github/workflows/codeql.yaml similarity index 100% rename from .github/workflows/codeql rename to .github/workflows/codeql.yaml From d8c61359877a2141b7c7e2fea8d02f6a8ebe4db9 Mon Sep 17 00:00:00 2001 From: Magni - God of Strength Date: Thu, 26 Jun 2025 05:56:26 -0400 Subject: [PATCH 12/22] Update label_pr.yaml --- .github/workflows/label_pr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/label_pr.yaml b/.github/workflows/label_pr.yaml index 4613569..fb6aba9 100644 --- a/.github/workflows/label_pr.yaml +++ b/.github/workflows/label_pr.yaml @@ -5,7 +5,7 @@ # file with configuration. For more information, see: # https://github.com/actions/labeler -name: Labeler +name: Pull Request Labeler on: [pull_request_target] jobs: From 39b1929118a19d39473a324dda919f31a19ec2ff Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Thu, 2 Oct 2025 02:57:44 +0000 Subject: [PATCH 13/22] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`t?= =?UTF-8?q?est`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docstrings generation was requested by @bcExpt1123. * https://github.com/bcExpt1123/java-alda/pull/3#issuecomment-3005417343 The following files were modified: * `src/main/java/org/alda/Main.java` * `src/main/java/org/alda/common/Utils.java` * `src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java` * `src/main/java/org/alda/structure/linkedList/deque/Node.java` * `src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java` * `src/main/java/org/alda/structure/linkedList/doubly/Node.java` * `src/main/java/org/alda/structure/linkedList/simple/Node.java` * `src/main/java/org/alda/structure/tree/bst/Node.java` * `src/main/java/org/alda/structure/tree/bst/bbt/AVL.java` --- src/main/java/org/alda/Main.java | 23 ++++++++------- src/main/java/org/alda/common/Utils.java | 13 +++++++++ .../linkedList/deque/DoublyEndedList.java | 5 ++++ .../alda/structure/linkedList/deque/Node.java | 5 ++-- .../linkedList/doubly/DoublyLinkedList.java | 4 ++- .../structure/linkedList/doubly/Node.java | 5 ++-- .../structure/linkedList/simple/Node.java | 5 ++-- .../org/alda/structure/tree/bst/Node.java | 4 +-- .../org/alda/structure/tree/bst/bbt/AVL.java | 29 +++++++++++++++++++ 9 files changed, 72 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/alda/Main.java b/src/main/java/org/alda/Main.java index 7b9f468..ecfed65 100644 --- a/src/main/java/org/alda/Main.java +++ b/src/main/java/org/alda/Main.java @@ -71,9 +71,9 @@ private static void displayMainMenu() { } /** - * Displays a submenu for selecting and testing different types of linked lists. + * Display a submenu to select and run linked list demonstrations. * - * Loops until the user chooses to return to the main menu. For each selection, runs the corresponding linked list demonstration and waits for user input before returning to the submenu. + * Loops until the user selects "Back to Main Menu". For each valid selection, invokes the corresponding linked list test and waits for the user to press Enter before showing the submenu again. */ private static void linkedListMenu() { while (true) { @@ -207,9 +207,9 @@ private static void pressEnterToContinue() { } /** - * Demonstrates basic operations on a simple linked list of integers, including appending, inserting, deleting, printing, and searching for elements. + * Demonstrates basic operations on a simple linked list of integers. * - * Initializes a simple linked list, performs a sequence of modifications, prints the list and head node, and displays search results for specific values. + * Performs appends, an insertion after the head, a deletion, prints the list and head node, and prints search results for selected values. */ public static void testSimpleLinkedList() { System.out.println("\n=== Initialize Simple Linked List ==="); @@ -297,9 +297,10 @@ public static void testSortedLinkedList() { } /** - * Demonstrates basic operations on a doubly ended linked list (deque) of integers. + * Demonstrates insertions at both front and end on a doubly ended linked list of integers. * - * Initializes a doubly ended list, performs a sequence of insertions at both the front and end, and prints the resulting list. + * Initializes a doubly-ended list, performs a sequence of appendFront and appendEnd operations, + * and prints the list in forward order. */ public static void testDoublyEndedList(){ System.out.println("\n=== Initialize Doubly Ended Linked List ==="); @@ -447,9 +448,9 @@ public static void testQueueLinkedList(){ } /** - * Demonstrates the usage of a priority queue by enqueuing integer elements with specified priorities and dequeuing several elements to show priority-based removal order. + * Demonstrates priority-based ordering by enqueuing integer elements with associated priorities and dequeuing several elements to show removal order. * - * This method initializes a priority queue, enqueues multiple integers with associated priorities, then dequeues and prints four elements to illustrate how the queue prioritizes elements. + * This method prints the enqueue actions and the first four dequeued values to illustrate how the priority queue selects items. */ public static void testPriorityQueue(){ System.out.println("\n=== Initialize Priority Queue ==="); @@ -480,10 +481,10 @@ public static void testPriorityQueue(){ } /** - * Demonstrates basic operations on a binary search tree, including insertion, inorder traversal, and search. + * Demonstrates insertion, inorder traversal, and search on a binary search tree. * - * Initializes a binary search tree of integers, inserts several values, prints the inorder traversal, - * and searches for the value 4, displaying whether it is found. + * Builds a BinarySearchTree, inserts the values 5, 3, 7, 1, 20, and 4, + * prints the tree's inorder traversal, and prints whether the value 4 is found. */ public static void testBST(){ System.out.println("\n=== Initialize Binary Search Tree ==="); diff --git a/src/main/java/org/alda/common/Utils.java b/src/main/java/org/alda/common/Utils.java index 3b4bf7e..f6fe0a7 100644 --- a/src/main/java/org/alda/common/Utils.java +++ b/src/main/java/org/alda/common/Utils.java @@ -3,6 +3,13 @@ import java.util.Arrays; public class Utils { + /** + * Join the elements of an int array into a single string using the specified delimiter. + * + * @param arr the array of integers to join + * @param delimiter the string placed between adjacent elements in the result + * @return the array elements separated by the delimiter; an empty string if the array has no elements + */ public static String intArrToStr(int[] arr, String delimiter) { return Arrays.stream(arr) .mapToObj(String::valueOf) @@ -10,6 +17,12 @@ public static String intArrToStr(int[] arr, String delimiter) { .orElse(""); } + /** + * Convert an integer array into a single string with elements separated by ", ". + * + * @param arr the integers to join + * @return a string with the array elements separated by ", ", or an empty string if the array is empty + */ public static String intArrToStr(int[] arr) { return intArrToStr(arr, ", "); } diff --git a/src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java b/src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java index 139206a..97252d9 100644 --- a/src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java +++ b/src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java @@ -63,6 +63,11 @@ public Node getTail() { return tail; } + /** + * Set the list's tail node. + * + * @param tail the node to use as the new last element of the list, or `null` to indicate there is no tail + */ public void setTail(Node tail) { this.tail = tail; } diff --git a/src/main/java/org/alda/structure/linkedList/deque/Node.java b/src/main/java/org/alda/structure/linkedList/deque/Node.java index 15dd1f9..880d8fa 100644 --- a/src/main/java/org/alda/structure/linkedList/deque/Node.java +++ b/src/main/java/org/alda/structure/linkedList/deque/Node.java @@ -44,8 +44,9 @@ public Node(T data){ } /** - * Constructs a new {@code Node} with {@code null} data. This is a default constructor - * that calls the main constructor with {@code null} as the data. + * Creates a new Node whose stored data is {@code null}. + * + * The created node's {@code next} and {@code prev} references are {@code null}. */ public Node(){ this(null); diff --git a/src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java b/src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java index 5dcc123..737fd92 100644 --- a/src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java +++ b/src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java @@ -78,7 +78,9 @@ public void prepend(T data) { } /** - * Prints each node's data in the list from head to tail, including adjacent nodes' data if present. + * Traverses the list from head to tail and prints each node's data. + * + * The traversal invokes each node's print method in sequence. */ public void print() { Node current = head; diff --git a/src/main/java/org/alda/structure/linkedList/doubly/Node.java b/src/main/java/org/alda/structure/linkedList/doubly/Node.java index 31d793b..7bd3b72 100644 --- a/src/main/java/org/alda/structure/linkedList/doubly/Node.java +++ b/src/main/java/org/alda/structure/linkedList/doubly/Node.java @@ -32,10 +32,9 @@ public class Node implements Printable { public Node prev; /** - * Constructs a new {@code Node} with the specified data. - * The {@code next} and {@code prev} references are initialized to {@code null}. + * Create a new Node holding the specified data with its adjacent references set to null. * - * @param data The data to store in the node. + * @param data the value to store in this node */ public Node(final T data) { this.data = data; diff --git a/src/main/java/org/alda/structure/linkedList/simple/Node.java b/src/main/java/org/alda/structure/linkedList/simple/Node.java index ef67119..e93e3fa 100644 --- a/src/main/java/org/alda/structure/linkedList/simple/Node.java +++ b/src/main/java/org/alda/structure/linkedList/simple/Node.java @@ -26,10 +26,11 @@ public class Node implements Printable { public Node next; /** - * Constructs a new {@code Node} with the specified data. + * Create a new Node containing the specified data. + * * The {@code next} reference is initialized to {@code null}. * - * @param data The data to store in the node. + * @param data the data element to store in the node */ public Node(T data) { this.data = data; diff --git a/src/main/java/org/alda/structure/tree/bst/Node.java b/src/main/java/org/alda/structure/tree/bst/Node.java index 80dfd71..4806ac5 100644 --- a/src/main/java/org/alda/structure/tree/bst/Node.java +++ b/src/main/java/org/alda/structure/tree/bst/Node.java @@ -22,9 +22,9 @@ public Node(T key){ } /** - * Prints the node's key and the keys of its left and right children, if present, to the standard output. + * Print the node's key and the keys of its left and right children to standard output. * - * The output format is: "Data: [key], Left: [left.key], Right: [right.key]". Child information is omitted if the respective child is null. + * The output is "Data: [key]" with ", Left: [left.key]" and ", Right: [right.key]" appended only when those children are present. */ public void print() { System.out.print("\nData: " + key); diff --git a/src/main/java/org/alda/structure/tree/bst/bbt/AVL.java b/src/main/java/org/alda/structure/tree/bst/bbt/AVL.java index a9db4da..38d1d05 100644 --- a/src/main/java/org/alda/structure/tree/bst/bbt/AVL.java +++ b/src/main/java/org/alda/structure/tree/bst/bbt/AVL.java @@ -38,6 +38,15 @@ */ public class AVL> { + /** + * Inserts a key into the subtree rooted at the given node and restores AVL balance. + * + * If the key already exists in the subtree, the tree is left unchanged (duplicates are not inserted). + * + * @param root the root of the subtree where the key should be inserted; may be null + * @param key the value to insert + * @return the root of the subtree after insertion and any necessary rebalancing + */ public Node insert(Node root, T key) { if (root == null) { return new Node<>(key); @@ -69,16 +78,36 @@ public Node insert(Node root, T key) { return root; } + /** + * Returns the height of the given node in the AVL subtree. + * + * @param root the node whose height is requested; may be {@code null} + * @return the node's height, or 0 if {@code root} is {@code null} + */ public Integer getHeight(Node root) { if(root == null) return 0; return root.height; } + /** + * Computes the balance factor of the given node. + * + * @param root the node whose balance factor to compute + * @return the balance factor defined as height(left subtree) minus height(right subtree); returns 0 if {@code root} is null + */ public Integer getBalance(Node root) { if (root == null) return 0; return getHeight(root.left) - getHeight(root.right); } + /** + * Performs a right rotation around the given subtree root. + * + *

Reassigns child pointers and updates node heights so the left child becomes the new root of the subtree.

+ * + * @param z the root of the subtree to rotate; must have a non-null left child + * @return the new root of the subtree after rotation + */ public Node rotateRight(Node z) { Node y = z.left; Node T = y.right; From 59d5b55fe04ffe71c3c1eecde3857a3f736b5346 Mon Sep 17 00:00:00 2001 From: bcExpt1123 Date: Mon, 6 Oct 2025 13:48:20 +0530 Subject: [PATCH 14/22] Rename package --- CONTRIBUTING.md | 2 +- README.md | 8 ++-- pom.xml | 2 +- src/main/java/org/{alda => dsa}/Main.java | 48 +++++++++---------- .../org/{alda => dsa}/common/Comparer.java | 2 +- .../org/{alda => dsa}/common/Printable.java | 2 +- .../java/org/{alda => dsa}/common/Utils.java | 2 +- .../stack/BalancedParenthesesCheck.java | 2 +- .../circular/CircularLinkedList.java | 4 +- .../structure/linkedList/circular/Node.java | 4 +- .../linkedList/deque/DoublyEndedList.java | 2 +- .../linkedList/deque/IDoublyEndedList.java | 4 +- .../structure/linkedList/deque/Node.java | 4 +- .../linkedList/doubly/DoublyLinkedList.java | 4 +- .../structure/linkedList/doubly/Node.java | 4 +- .../linkedList/simple/ISimpleLinkedList.java | 4 +- .../structure/linkedList/simple/Node.java | 4 +- .../linkedList/simple/SimpleLinkedList.java | 2 +- .../linkedList/sorted/ISortedLinkedList.java | 6 +-- .../linkedList/sorted/SortedLinkedList.java | 8 ++-- .../{alda => dsa}/structure/queue/IQueue.java | 2 +- .../{alda => dsa}/structure/queue/Queue.java | 2 +- .../structure/queue/array/QueueArray.java | 4 +- .../queue/linkedList/QueueLinkedList.java | 6 +-- .../queue/priority/IPriorityQueue.java | 2 +- .../structure/queue/priority/Node.java | 2 +- .../queue/priority/PriorityQueue.java | 4 +- .../structure/stack/array/IStackArray.java | 2 +- .../structure/stack/array/StackArray.java | 2 +- .../stack/linkedList/IStackLinkedList.java | 2 +- .../stack/linkedList/StackLinkedList.java | 4 +- .../structure/tree/bst/BinarySearchTree.java | 2 +- .../structure/tree/bst/Node.java | 4 +- .../structure/tree/bst/bbt/AVL.java | 2 +- .../structure/tree/bst/bbt/AVLTest.java | 4 +- .../structure/tree/bst/bbt/RBT.java | 2 +- .../{alda => dsa}/common/ComparerTest.java | 2 +- .../org/{alda => dsa}/common/UtilsTest.java | 2 +- 38 files changed, 85 insertions(+), 83 deletions(-) rename src/main/java/org/{alda => dsa}/Main.java (93%) rename src/main/java/org/{alda => dsa}/common/Comparer.java (99%) rename src/main/java/org/{alda => dsa}/common/Printable.java (96%) rename src/main/java/org/{alda => dsa}/common/Utils.java (97%) rename src/main/java/org/{alda => dsa}/sample/stack/BalancedParenthesesCheck.java (97%) rename src/main/java/org/{alda => dsa}/structure/linkedList/circular/CircularLinkedList.java (96%) rename src/main/java/org/{alda => dsa}/structure/linkedList/circular/Node.java (95%) rename src/main/java/org/{alda => dsa}/structure/linkedList/deque/DoublyEndedList.java (97%) rename src/main/java/org/{alda => dsa}/structure/linkedList/deque/IDoublyEndedList.java (94%) rename src/main/java/org/{alda => dsa}/structure/linkedList/deque/Node.java (95%) rename src/main/java/org/{alda => dsa}/structure/linkedList/doubly/DoublyLinkedList.java (96%) rename src/main/java/org/{alda => dsa}/structure/linkedList/doubly/Node.java (95%) rename src/main/java/org/{alda => dsa}/structure/linkedList/simple/ISimpleLinkedList.java (95%) rename src/main/java/org/{alda => dsa}/structure/linkedList/simple/Node.java (94%) rename src/main/java/org/{alda => dsa}/structure/linkedList/simple/SimpleLinkedList.java (98%) rename src/main/java/org/{alda => dsa}/structure/linkedList/sorted/ISortedLinkedList.java (91%) rename src/main/java/org/{alda => dsa}/structure/linkedList/sorted/SortedLinkedList.java (90%) rename src/main/java/org/{alda => dsa}/structure/queue/IQueue.java (96%) rename src/main/java/org/{alda => dsa}/structure/queue/Queue.java (97%) rename src/main/java/org/{alda => dsa}/structure/queue/array/QueueArray.java (93%) rename src/main/java/org/{alda => dsa}/structure/queue/linkedList/QueueLinkedList.java (91%) rename src/main/java/org/{alda => dsa}/structure/queue/priority/IPriorityQueue.java (70%) rename src/main/java/org/{alda => dsa}/structure/queue/priority/Node.java (82%) rename src/main/java/org/{alda => dsa}/structure/queue/priority/PriorityQueue.java (92%) rename src/main/java/org/{alda => dsa}/structure/stack/array/IStackArray.java (90%) rename src/main/java/org/{alda => dsa}/structure/stack/array/StackArray.java (94%) rename src/main/java/org/{alda => dsa}/structure/stack/linkedList/IStackLinkedList.java (95%) rename src/main/java/org/{alda => dsa}/structure/stack/linkedList/StackLinkedList.java (91%) rename src/main/java/org/{alda => dsa}/structure/tree/bst/BinarySearchTree.java (97%) rename src/main/java/org/{alda => dsa}/structure/tree/bst/Node.java (92%) rename src/main/java/org/{alda => dsa}/structure/tree/bst/bbt/AVL.java (99%) rename src/main/java/org/{alda => dsa}/structure/tree/bst/bbt/AVLTest.java (95%) rename src/main/java/org/{alda => dsa}/structure/tree/bst/bbt/RBT.java (96%) rename src/test/java/org/{alda => dsa}/common/ComparerTest.java (98%) rename src/test/java/org/{alda => dsa}/common/UtilsTest.java (97%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4057c31..3fc95da 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,7 +8,7 @@ Thank you for taking the time to contribute to this project! Here are a few guid 2. **Clone the repository**: Clone your forked repository to your local machine using the following command: ```sh - git clone https://github.com/your-username/java-alda.git + git clone https://github.com/your-username/java-dsa.git ``` 3. **Create a branch**: Create a new branch for your work using the following command: diff --git a/README.md b/README.md index 304c0fa..3e89e94 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Java Algorithms and Data Structures +# Java Data Structures and Algorithms This repository contains implementations of various algorithms and data structures in Java. It is intended as a resource for learning and reference. @@ -94,11 +94,11 @@ Implementation and usage of graphs. 1. Clone the repository: ```sh - git clone https://github.com/bcExpt1123/java-alda.git + git clone https://github.com/bcExpt1123/java-dsa.git ``` 2. Navigate to the project directory: ```sh - cd java-alda + cd java-dsa ``` ## Usage @@ -107,10 +107,12 @@ Run code: ```sh mvn clean compile exec:java ``` + Run test: ```sh mvn test ``` + Run Check style: ```sh mvn checkstyle:check diff --git a/pom.xml b/pom.xml index f73fdbb..deb495c 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ 23 23 UTF-8 - org.alda.Main + org.dsa.Main diff --git a/src/main/java/org/alda/Main.java b/src/main/java/org/dsa/Main.java similarity index 93% rename from src/main/java/org/alda/Main.java rename to src/main/java/org/dsa/Main.java index ecfed65..fba5e7c 100644 --- a/src/main/java/org/alda/Main.java +++ b/src/main/java/org/dsa/Main.java @@ -1,26 +1,26 @@ -package org.alda; - -import org.alda.structure.linkedList.circular.CircularLinkedList; -import org.alda.structure.linkedList.deque.DoublyEndedList; -import org.alda.structure.linkedList.deque.IDoublyEndedList; -import org.alda.structure.linkedList.doubly.DoublyLinkedList; -import org.alda.structure.linkedList.simple.ISimpleLinkedList; -import org.alda.structure.linkedList.simple.Node; -import org.alda.structure.linkedList.simple.SimpleLinkedList; -import org.alda.structure.linkedList.sorted.ISortedLinkedList; -import org.alda.structure.linkedList.sorted.SortedLinkedList; -import org.alda.structure.queue.IQueue; -import org.alda.structure.queue.Queue; -import org.alda.structure.queue.array.QueueArray; -import org.alda.structure.queue.linkedList.QueueLinkedList; -import org.alda.structure.queue.priority.IPriorityQueue; -import org.alda.structure.queue.priority.PriorityQueue; -import org.alda.structure.stack.array.IStackArray; -import org.alda.structure.stack.array.StackArray; -import org.alda.structure.stack.linkedList.IStackLinkedList; -import org.alda.structure.stack.linkedList.StackLinkedList; -import org.alda.structure.tree.bst.BinarySearchTree; -import org.alda.structure.tree.bst.bbt.AVLTest; +package org.dsa; + +import org.dsa.structure.linkedList.circular.CircularLinkedList; +import org.dsa.structure.linkedList.deque.DoublyEndedList; +import org.dsa.structure.linkedList.deque.IDoublyEndedList; +import org.dsa.structure.linkedList.doubly.DoublyLinkedList; +import org.dsa.structure.linkedList.simple.ISimpleLinkedList; +import org.dsa.structure.linkedList.simple.Node; +import org.dsa.structure.linkedList.simple.SimpleLinkedList; +import org.dsa.structure.linkedList.sorted.ISortedLinkedList; +import org.dsa.structure.linkedList.sorted.SortedLinkedList; +import org.dsa.structure.queue.IQueue; +import org.dsa.structure.queue.Queue; +import org.dsa.structure.queue.array.QueueArray; +import org.dsa.structure.queue.linkedList.QueueLinkedList; +import org.dsa.structure.queue.priority.IPriorityQueue; +import org.dsa.structure.queue.priority.PriorityQueue; +import org.dsa.structure.stack.array.IStackArray; +import org.dsa.structure.stack.array.StackArray; +import org.dsa.structure.stack.linkedList.IStackLinkedList; +import org.dsa.structure.stack.linkedList.StackLinkedList; +import org.dsa.structure.tree.bst.BinarySearchTree; +import org.dsa.structure.tree.bst.bbt.AVLTest; import java.util.Scanner; @@ -501,7 +501,7 @@ public static void testBST(){ System.out.println("- Inorder Traversal "); System.out.println(bst.inorderTraversal()); System.out.print("\nSearch for 4: "); - org.alda.structure.tree.bst.Node node = bst.search(4); + org.dsa.structure.tree.bst.Node node = bst.search(4); if (node != null) System.out.println("true"); else System.out.println("false"); } diff --git a/src/main/java/org/alda/common/Comparer.java b/src/main/java/org/dsa/common/Comparer.java similarity index 99% rename from src/main/java/org/alda/common/Comparer.java rename to src/main/java/org/dsa/common/Comparer.java index 3977588..8977a4f 100644 --- a/src/main/java/org/alda/common/Comparer.java +++ b/src/main/java/org/dsa/common/Comparer.java @@ -1,4 +1,4 @@ -package org.alda.common; +package org.dsa.common; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/common/Printable.java b/src/main/java/org/dsa/common/Printable.java similarity index 96% rename from src/main/java/org/alda/common/Printable.java rename to src/main/java/org/dsa/common/Printable.java index 47a1aeb..bbc2c81 100644 --- a/src/main/java/org/alda/common/Printable.java +++ b/src/main/java/org/dsa/common/Printable.java @@ -1,4 +1,4 @@ -package org.alda.common; +package org.dsa.common; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/common/Utils.java b/src/main/java/org/dsa/common/Utils.java similarity index 97% rename from src/main/java/org/alda/common/Utils.java rename to src/main/java/org/dsa/common/Utils.java index f6fe0a7..d7733cc 100644 --- a/src/main/java/org/alda/common/Utils.java +++ b/src/main/java/org/dsa/common/Utils.java @@ -1,4 +1,4 @@ -package org.alda.common; +package org.dsa.common; import java.util.Arrays; diff --git a/src/main/java/org/alda/sample/stack/BalancedParenthesesCheck.java b/src/main/java/org/dsa/sample/stack/BalancedParenthesesCheck.java similarity index 97% rename from src/main/java/org/alda/sample/stack/BalancedParenthesesCheck.java rename to src/main/java/org/dsa/sample/stack/BalancedParenthesesCheck.java index a7ed29f..f8313c8 100644 --- a/src/main/java/org/alda/sample/stack/BalancedParenthesesCheck.java +++ b/src/main/java/org/dsa/sample/stack/BalancedParenthesesCheck.java @@ -1,4 +1,4 @@ -package org.alda.sample.stack; +package org.dsa.sample.stack; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/main/java/org/alda/structure/linkedList/circular/CircularLinkedList.java b/src/main/java/org/dsa/structure/linkedList/circular/CircularLinkedList.java similarity index 96% rename from src/main/java/org/alda/structure/linkedList/circular/CircularLinkedList.java rename to src/main/java/org/dsa/structure/linkedList/circular/CircularLinkedList.java index 059bf43..eb4fbf0 100644 --- a/src/main/java/org/alda/structure/linkedList/circular/CircularLinkedList.java +++ b/src/main/java/org/dsa/structure/linkedList/circular/CircularLinkedList.java @@ -1,6 +1,6 @@ -package org.alda.structure.linkedList.circular; +package org.dsa.structure.linkedList.circular; -import org.alda.common.Printable; +import org.dsa.common.Printable; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/structure/linkedList/circular/Node.java b/src/main/java/org/dsa/structure/linkedList/circular/Node.java similarity index 95% rename from src/main/java/org/alda/structure/linkedList/circular/Node.java rename to src/main/java/org/dsa/structure/linkedList/circular/Node.java index 7d38727..b351797 100644 --- a/src/main/java/org/alda/structure/linkedList/circular/Node.java +++ b/src/main/java/org/dsa/structure/linkedList/circular/Node.java @@ -1,6 +1,6 @@ -package org.alda.structure.linkedList.circular; +package org.dsa.structure.linkedList.circular; -import org.alda.common.Printable; +import org.dsa.common.Printable; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java b/src/main/java/org/dsa/structure/linkedList/deque/DoublyEndedList.java similarity index 97% rename from src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java rename to src/main/java/org/dsa/structure/linkedList/deque/DoublyEndedList.java index 97252d9..9ad6e0c 100644 --- a/src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java +++ b/src/main/java/org/dsa/structure/linkedList/deque/DoublyEndedList.java @@ -1,4 +1,4 @@ -package org.alda.structure.linkedList.deque; +package org.dsa.structure.linkedList.deque; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/structure/linkedList/deque/IDoublyEndedList.java b/src/main/java/org/dsa/structure/linkedList/deque/IDoublyEndedList.java similarity index 94% rename from src/main/java/org/alda/structure/linkedList/deque/IDoublyEndedList.java rename to src/main/java/org/dsa/structure/linkedList/deque/IDoublyEndedList.java index a1d262e..958ef32 100644 --- a/src/main/java/org/alda/structure/linkedList/deque/IDoublyEndedList.java +++ b/src/main/java/org/dsa/structure/linkedList/deque/IDoublyEndedList.java @@ -1,6 +1,6 @@ -package org.alda.structure.linkedList.deque; +package org.dsa.structure.linkedList.deque; -import org.alda.common.Printable; +import org.dsa.common.Printable; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/structure/linkedList/deque/Node.java b/src/main/java/org/dsa/structure/linkedList/deque/Node.java similarity index 95% rename from src/main/java/org/alda/structure/linkedList/deque/Node.java rename to src/main/java/org/dsa/structure/linkedList/deque/Node.java index 880d8fa..38e5277 100644 --- a/src/main/java/org/alda/structure/linkedList/deque/Node.java +++ b/src/main/java/org/dsa/structure/linkedList/deque/Node.java @@ -1,6 +1,6 @@ -package org.alda.structure.linkedList.deque; +package org.dsa.structure.linkedList.deque; -import org.alda.common.Printable; +import org.dsa.common.Printable; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java b/src/main/java/org/dsa/structure/linkedList/doubly/DoublyLinkedList.java similarity index 96% rename from src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java rename to src/main/java/org/dsa/structure/linkedList/doubly/DoublyLinkedList.java index 737fd92..191f5bf 100644 --- a/src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java +++ b/src/main/java/org/dsa/structure/linkedList/doubly/DoublyLinkedList.java @@ -1,6 +1,6 @@ -package org.alda.structure.linkedList.doubly; +package org.dsa.structure.linkedList.doubly; -import org.alda.common.Printable; +import org.dsa.common.Printable; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/structure/linkedList/doubly/Node.java b/src/main/java/org/dsa/structure/linkedList/doubly/Node.java similarity index 95% rename from src/main/java/org/alda/structure/linkedList/doubly/Node.java rename to src/main/java/org/dsa/structure/linkedList/doubly/Node.java index 7bd3b72..afa6213 100644 --- a/src/main/java/org/alda/structure/linkedList/doubly/Node.java +++ b/src/main/java/org/dsa/structure/linkedList/doubly/Node.java @@ -1,6 +1,6 @@ -package org.alda.structure.linkedList.doubly; +package org.dsa.structure.linkedList.doubly; -import org.alda.common.Printable; +import org.dsa.common.Printable; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/structure/linkedList/simple/ISimpleLinkedList.java b/src/main/java/org/dsa/structure/linkedList/simple/ISimpleLinkedList.java similarity index 95% rename from src/main/java/org/alda/structure/linkedList/simple/ISimpleLinkedList.java rename to src/main/java/org/dsa/structure/linkedList/simple/ISimpleLinkedList.java index 93bb6d4..70cbec7 100644 --- a/src/main/java/org/alda/structure/linkedList/simple/ISimpleLinkedList.java +++ b/src/main/java/org/dsa/structure/linkedList/simple/ISimpleLinkedList.java @@ -1,6 +1,6 @@ -package org.alda.structure.linkedList.simple; +package org.dsa.structure.linkedList.simple; -import org.alda.common.Printable; +import org.dsa.common.Printable; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/structure/linkedList/simple/Node.java b/src/main/java/org/dsa/structure/linkedList/simple/Node.java similarity index 94% rename from src/main/java/org/alda/structure/linkedList/simple/Node.java rename to src/main/java/org/dsa/structure/linkedList/simple/Node.java index e93e3fa..4a1a19d 100644 --- a/src/main/java/org/alda/structure/linkedList/simple/Node.java +++ b/src/main/java/org/dsa/structure/linkedList/simple/Node.java @@ -1,6 +1,6 @@ -package org.alda.structure.linkedList.simple; +package org.dsa.structure.linkedList.simple; -import org.alda.common.Printable; +import org.dsa.common.Printable; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/structure/linkedList/simple/SimpleLinkedList.java b/src/main/java/org/dsa/structure/linkedList/simple/SimpleLinkedList.java similarity index 98% rename from src/main/java/org/alda/structure/linkedList/simple/SimpleLinkedList.java rename to src/main/java/org/dsa/structure/linkedList/simple/SimpleLinkedList.java index a430fa5..012d4d9 100644 --- a/src/main/java/org/alda/structure/linkedList/simple/SimpleLinkedList.java +++ b/src/main/java/org/dsa/structure/linkedList/simple/SimpleLinkedList.java @@ -1,4 +1,4 @@ -package org.alda.structure.linkedList.simple; +package org.dsa.structure.linkedList.simple; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/structure/linkedList/sorted/ISortedLinkedList.java b/src/main/java/org/dsa/structure/linkedList/sorted/ISortedLinkedList.java similarity index 91% rename from src/main/java/org/alda/structure/linkedList/sorted/ISortedLinkedList.java rename to src/main/java/org/dsa/structure/linkedList/sorted/ISortedLinkedList.java index 9640b87..b0e5886 100644 --- a/src/main/java/org/alda/structure/linkedList/sorted/ISortedLinkedList.java +++ b/src/main/java/org/dsa/structure/linkedList/sorted/ISortedLinkedList.java @@ -1,7 +1,7 @@ -package org.alda.structure.linkedList.sorted; +package org.dsa.structure.linkedList.sorted; -import org.alda.common.Printable; -import org.alda.structure.linkedList.simple.Node; +import org.dsa.common.Printable; +import org.dsa.structure.linkedList.simple.Node; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/structure/linkedList/sorted/SortedLinkedList.java b/src/main/java/org/dsa/structure/linkedList/sorted/SortedLinkedList.java similarity index 90% rename from src/main/java/org/alda/structure/linkedList/sorted/SortedLinkedList.java rename to src/main/java/org/dsa/structure/linkedList/sorted/SortedLinkedList.java index aefb9a8..f1de392 100644 --- a/src/main/java/org/alda/structure/linkedList/sorted/SortedLinkedList.java +++ b/src/main/java/org/dsa/structure/linkedList/sorted/SortedLinkedList.java @@ -1,8 +1,8 @@ -package org.alda.structure.linkedList.sorted; +package org.dsa.structure.linkedList.sorted; -import org.alda.common.Comparer; -import org.alda.structure.linkedList.simple.Node; -import org.alda.structure.linkedList.simple.SimpleLinkedList; +import org.dsa.common.Comparer; +import org.dsa.structure.linkedList.simple.Node; +import org.dsa.structure.linkedList.simple.SimpleLinkedList; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/structure/queue/IQueue.java b/src/main/java/org/dsa/structure/queue/IQueue.java similarity index 96% rename from src/main/java/org/alda/structure/queue/IQueue.java rename to src/main/java/org/dsa/structure/queue/IQueue.java index 9e6a4cf..4c02d95 100644 --- a/src/main/java/org/alda/structure/queue/IQueue.java +++ b/src/main/java/org/dsa/structure/queue/IQueue.java @@ -1,4 +1,4 @@ -package org.alda.structure.queue; +package org.dsa.structure.queue; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/structure/queue/Queue.java b/src/main/java/org/dsa/structure/queue/Queue.java similarity index 97% rename from src/main/java/org/alda/structure/queue/Queue.java rename to src/main/java/org/dsa/structure/queue/Queue.java index 38fe816..b9c1316 100644 --- a/src/main/java/org/alda/structure/queue/Queue.java +++ b/src/main/java/org/dsa/structure/queue/Queue.java @@ -1,4 +1,4 @@ -package org.alda.structure.queue; +package org.dsa.structure.queue; import java.util.ArrayList; diff --git a/src/main/java/org/alda/structure/queue/array/QueueArray.java b/src/main/java/org/dsa/structure/queue/array/QueueArray.java similarity index 93% rename from src/main/java/org/alda/structure/queue/array/QueueArray.java rename to src/main/java/org/dsa/structure/queue/array/QueueArray.java index f0680d4..f92dfc1 100644 --- a/src/main/java/org/alda/structure/queue/array/QueueArray.java +++ b/src/main/java/org/dsa/structure/queue/array/QueueArray.java @@ -1,6 +1,6 @@ -package org.alda.structure.queue.array; +package org.dsa.structure.queue.array; -import org.alda.structure.queue.IQueue; +import org.dsa.structure.queue.IQueue; import java.util.ArrayList; diff --git a/src/main/java/org/alda/structure/queue/linkedList/QueueLinkedList.java b/src/main/java/org/dsa/structure/queue/linkedList/QueueLinkedList.java similarity index 91% rename from src/main/java/org/alda/structure/queue/linkedList/QueueLinkedList.java rename to src/main/java/org/dsa/structure/queue/linkedList/QueueLinkedList.java index d33293f..b5eaf3f 100644 --- a/src/main/java/org/alda/structure/queue/linkedList/QueueLinkedList.java +++ b/src/main/java/org/dsa/structure/queue/linkedList/QueueLinkedList.java @@ -1,7 +1,7 @@ -package org.alda.structure.queue.linkedList; +package org.dsa.structure.queue.linkedList; -import org.alda.structure.linkedList.simple.Node; -import org.alda.structure.queue.IQueue; +import org.dsa.structure.linkedList.simple.Node; +import org.dsa.structure.queue.IQueue; import java.util.ArrayList; diff --git a/src/main/java/org/alda/structure/queue/priority/IPriorityQueue.java b/src/main/java/org/dsa/structure/queue/priority/IPriorityQueue.java similarity index 70% rename from src/main/java/org/alda/structure/queue/priority/IPriorityQueue.java rename to src/main/java/org/dsa/structure/queue/priority/IPriorityQueue.java index 8a6a32d..2fff489 100644 --- a/src/main/java/org/alda/structure/queue/priority/IPriorityQueue.java +++ b/src/main/java/org/dsa/structure/queue/priority/IPriorityQueue.java @@ -1,4 +1,4 @@ -package org.alda.structure.queue.priority; +package org.dsa.structure.queue.priority; public interface IPriorityQueue { void enqueue(T element, Integer priority); diff --git a/src/main/java/org/alda/structure/queue/priority/Node.java b/src/main/java/org/dsa/structure/queue/priority/Node.java similarity index 82% rename from src/main/java/org/alda/structure/queue/priority/Node.java rename to src/main/java/org/dsa/structure/queue/priority/Node.java index b11be77..6458986 100644 --- a/src/main/java/org/alda/structure/queue/priority/Node.java +++ b/src/main/java/org/dsa/structure/queue/priority/Node.java @@ -1,4 +1,4 @@ -package org.alda.structure.queue.priority; +package org.dsa.structure.queue.priority; public class Node { public T data; diff --git a/src/main/java/org/alda/structure/queue/priority/PriorityQueue.java b/src/main/java/org/dsa/structure/queue/priority/PriorityQueue.java similarity index 92% rename from src/main/java/org/alda/structure/queue/priority/PriorityQueue.java rename to src/main/java/org/dsa/structure/queue/priority/PriorityQueue.java index f82a525..5ec4c2c 100644 --- a/src/main/java/org/alda/structure/queue/priority/PriorityQueue.java +++ b/src/main/java/org/dsa/structure/queue/priority/PriorityQueue.java @@ -1,6 +1,6 @@ -package org.alda.structure.queue.priority; +package org.dsa.structure.queue.priority; -import org.alda.common.Comparer; +import org.dsa.common.Comparer; public class PriorityQueue implements IPriorityQueue { private Node head; diff --git a/src/main/java/org/alda/structure/stack/array/IStackArray.java b/src/main/java/org/dsa/structure/stack/array/IStackArray.java similarity index 90% rename from src/main/java/org/alda/structure/stack/array/IStackArray.java rename to src/main/java/org/dsa/structure/stack/array/IStackArray.java index 9b32775..5cc1765 100644 --- a/src/main/java/org/alda/structure/stack/array/IStackArray.java +++ b/src/main/java/org/dsa/structure/stack/array/IStackArray.java @@ -1,4 +1,4 @@ -package org.alda.structure.stack.array; +package org.dsa.structure.stack.array; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/structure/stack/array/StackArray.java b/src/main/java/org/dsa/structure/stack/array/StackArray.java similarity index 94% rename from src/main/java/org/alda/structure/stack/array/StackArray.java rename to src/main/java/org/dsa/structure/stack/array/StackArray.java index ed56215..516f338 100644 --- a/src/main/java/org/alda/structure/stack/array/StackArray.java +++ b/src/main/java/org/dsa/structure/stack/array/StackArray.java @@ -1,4 +1,4 @@ -package org.alda.structure.stack.array; +package org.dsa.structure.stack.array; import java.util.ArrayList; diff --git a/src/main/java/org/alda/structure/stack/linkedList/IStackLinkedList.java b/src/main/java/org/dsa/structure/stack/linkedList/IStackLinkedList.java similarity index 95% rename from src/main/java/org/alda/structure/stack/linkedList/IStackLinkedList.java rename to src/main/java/org/dsa/structure/stack/linkedList/IStackLinkedList.java index 2c48cdc..966debc 100644 --- a/src/main/java/org/alda/structure/stack/linkedList/IStackLinkedList.java +++ b/src/main/java/org/dsa/structure/stack/linkedList/IStackLinkedList.java @@ -1,4 +1,4 @@ -package org.alda.structure.stack.linkedList; +package org.dsa.structure.stack.linkedList; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/structure/stack/linkedList/StackLinkedList.java b/src/main/java/org/dsa/structure/stack/linkedList/StackLinkedList.java similarity index 91% rename from src/main/java/org/alda/structure/stack/linkedList/StackLinkedList.java rename to src/main/java/org/dsa/structure/stack/linkedList/StackLinkedList.java index 72e3c01..99edf73 100644 --- a/src/main/java/org/alda/structure/stack/linkedList/StackLinkedList.java +++ b/src/main/java/org/dsa/structure/stack/linkedList/StackLinkedList.java @@ -1,6 +1,6 @@ -package org.alda.structure.stack.linkedList; +package org.dsa.structure.stack.linkedList; -import org.alda.structure.linkedList.simple.Node; +import org.dsa.structure.linkedList.simple.Node; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/structure/tree/bst/BinarySearchTree.java b/src/main/java/org/dsa/structure/tree/bst/BinarySearchTree.java similarity index 97% rename from src/main/java/org/alda/structure/tree/bst/BinarySearchTree.java rename to src/main/java/org/dsa/structure/tree/bst/BinarySearchTree.java index adfbab2..bc75233 100644 --- a/src/main/java/org/alda/structure/tree/bst/BinarySearchTree.java +++ b/src/main/java/org/dsa/structure/tree/bst/BinarySearchTree.java @@ -1,4 +1,4 @@ -package org.alda.structure.tree.bst; +package org.dsa.structure.tree.bst; import java.util.ArrayList; diff --git a/src/main/java/org/alda/structure/tree/bst/Node.java b/src/main/java/org/dsa/structure/tree/bst/Node.java similarity index 92% rename from src/main/java/org/alda/structure/tree/bst/Node.java rename to src/main/java/org/dsa/structure/tree/bst/Node.java index 4806ac5..39badcd 100644 --- a/src/main/java/org/alda/structure/tree/bst/Node.java +++ b/src/main/java/org/dsa/structure/tree/bst/Node.java @@ -1,6 +1,6 @@ -package org.alda.structure.tree.bst; +package org.dsa.structure.tree.bst; -import org.alda.common.Printable; +import org.dsa.common.Printable; /** * Node for binary search tree diff --git a/src/main/java/org/alda/structure/tree/bst/bbt/AVL.java b/src/main/java/org/dsa/structure/tree/bst/bbt/AVL.java similarity index 99% rename from src/main/java/org/alda/structure/tree/bst/bbt/AVL.java rename to src/main/java/org/dsa/structure/tree/bst/bbt/AVL.java index 38d1d05..39c8ad1 100644 --- a/src/main/java/org/alda/structure/tree/bst/bbt/AVL.java +++ b/src/main/java/org/dsa/structure/tree/bst/bbt/AVL.java @@ -1,4 +1,4 @@ -package org.alda.structure.tree.bst.bbt; +package org.dsa.structure.tree.bst.bbt; /** * @author bcExpt1123 diff --git a/src/main/java/org/alda/structure/tree/bst/bbt/AVLTest.java b/src/main/java/org/dsa/structure/tree/bst/bbt/AVLTest.java similarity index 95% rename from src/main/java/org/alda/structure/tree/bst/bbt/AVLTest.java rename to src/main/java/org/dsa/structure/tree/bst/bbt/AVLTest.java index 01e082d..fa27da6 100644 --- a/src/main/java/org/alda/structure/tree/bst/bbt/AVLTest.java +++ b/src/main/java/org/dsa/structure/tree/bst/bbt/AVLTest.java @@ -1,6 +1,6 @@ -package org.alda.structure.tree.bst.bbt; +package org.dsa.structure.tree.bst.bbt; -import org.alda.common.Utils; +import org.dsa.common.Utils; public class AVLTest { public static void main(String[] args) { diff --git a/src/main/java/org/alda/structure/tree/bst/bbt/RBT.java b/src/main/java/org/dsa/structure/tree/bst/bbt/RBT.java similarity index 96% rename from src/main/java/org/alda/structure/tree/bst/bbt/RBT.java rename to src/main/java/org/dsa/structure/tree/bst/bbt/RBT.java index 380fb2a..6f36828 100644 --- a/src/main/java/org/alda/structure/tree/bst/bbt/RBT.java +++ b/src/main/java/org/dsa/structure/tree/bst/bbt/RBT.java @@ -1,4 +1,4 @@ -package org.alda.structure.tree.bst.bbt; +package org.dsa.structure.tree.bst.bbt; /** * @author bcExpt1123 diff --git a/src/test/java/org/alda/common/ComparerTest.java b/src/test/java/org/dsa/common/ComparerTest.java similarity index 98% rename from src/test/java/org/alda/common/ComparerTest.java rename to src/test/java/org/dsa/common/ComparerTest.java index fb27966..77be598 100644 --- a/src/test/java/org/alda/common/ComparerTest.java +++ b/src/test/java/org/dsa/common/ComparerTest.java @@ -1,4 +1,4 @@ -package org.alda.common; +package org.dsa.common; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; diff --git a/src/test/java/org/alda/common/UtilsTest.java b/src/test/java/org/dsa/common/UtilsTest.java similarity index 97% rename from src/test/java/org/alda/common/UtilsTest.java rename to src/test/java/org/dsa/common/UtilsTest.java index b0a07f7..5d4516b 100644 --- a/src/test/java/org/alda/common/UtilsTest.java +++ b/src/test/java/org/dsa/common/UtilsTest.java @@ -1,4 +1,4 @@ -package org.alda.common; +package org.dsa.common; import org.junit.jupiter.api.Test; From abcce9b0da8228235809776081649115423a3fc0 Mon Sep 17 00:00:00 2001 From: bcExpt1123 Date: Mon, 6 Oct 2025 13:54:55 +0530 Subject: [PATCH 15/22] Update summarize new issue workflwo --- .github/workflows/summarize_new_issue.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/summarize_new_issue.yaml b/.github/workflows/summarize_new_issue.yaml index 9b07bb8..eb75f8f 100644 --- a/.github/workflows/summarize_new_issue.yaml +++ b/.github/workflows/summarize_new_issue.yaml @@ -9,7 +9,6 @@ jobs: runs-on: ubuntu-latest permissions: issues: write - models: read contents: read steps: From 9c612366f82a5c48d349cde203d46e22c5d69a0c Mon Sep 17 00:00:00 2001 From: Magni - God of Strength Date: Mon, 6 Oct 2025 04:25:55 -0400 Subject: [PATCH 16/22] Update .github/workflows/summarize_new_issue.yaml Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .github/workflows/summarize_new_issue.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/summarize_new_issue.yaml b/.github/workflows/summarize_new_issue.yaml index eb75f8f..d072763 100644 --- a/.github/workflows/summarize_new_issue.yaml +++ b/.github/workflows/summarize_new_issue.yaml @@ -25,9 +25,9 @@ jobs: Body: ${{ github.event.issue.body }} - name: Comment with AI summary - run: | - gh issue comment $ISSUE_NUMBER --body '${{ steps.inference.outputs.response }}' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} ISSUE_NUMBER: ${{ github.event.issue.number }} RESPONSE: ${{ steps.inference.outputs.response }} + run: | + gh issue comment "$ISSUE_NUMBER" --body "$RESPONSE" From ba286a2e9b9fadc41d493f76362fd86f4ece7063 Mon Sep 17 00:00:00 2001 From: Magni - God of Strength Date: Mon, 6 Oct 2025 04:35:07 -0400 Subject: [PATCH 17/22] Update src/main/java/org/dsa/common/Utils.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/main/java/org/dsa/common/Utils.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/dsa/common/Utils.java b/src/main/java/org/dsa/common/Utils.java index d7733cc..0738908 100644 --- a/src/main/java/org/dsa/common/Utils.java +++ b/src/main/java/org/dsa/common/Utils.java @@ -11,10 +11,13 @@ public class Utils { * @return the array elements separated by the delimiter; an empty string if the array has no elements */ public static String intArrToStr(int[] arr, String delimiter) { + if (arr == null || delimiter == null) { + throw new IllegalArgumentException("Array and delimiter must not be null"); + } return Arrays.stream(arr) .mapToObj(String::valueOf) - .reduce((a, b) -> a + delimiter + b) - .orElse(""); +- .reduce((a, b) -> a + delimiter + b) + .collect(java.util.stream.Collectors.joining(delimiter)); } /** From a64306d232a6b78edf55ab8c491e5a66bbebb56c Mon Sep 17 00:00:00 2001 From: bcExpt1123 Date: Mon, 6 Oct 2025 14:13:50 +0530 Subject: [PATCH 18/22] Update Main.java - scanner, and revert Utils --- src/main/java/org/dsa/Main.java | 61 ++++++++++++------------- src/main/java/org/dsa/common/Utils.java | 7 +-- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/dsa/Main.java b/src/main/java/org/dsa/Main.java index fba5e7c..4dbcd97 100644 --- a/src/main/java/org/dsa/Main.java +++ b/src/main/java/org/dsa/Main.java @@ -28,8 +28,6 @@ * Main class demonstrating various data structures with an interactive menu. */ public class Main { - private static final Scanner scanner = new Scanner(System.in); - /** * Launches the interactive console application for demonstrating various data structures. * @@ -38,24 +36,25 @@ public class Main { * @param args command-line arguments (not used) */ public static void main(String[] args) { - boolean running = true; - - while (running) { - displayMainMenu(); - int choice = getMenuChoice(5); - - switch (choice) { - case 1 -> linkedListMenu(); - case 2 -> stackMenu(); - case 3 -> queueMenu(); - case 4 -> treeMenu(); - case 5 -> { - System.out.println("\nThank you for using Data Structure Demo!"); - running = false; + try (Scanner scanner = new Scanner(System.in)) { + boolean running = true; + + while (running) { + displayMainMenu(); + int choice = getMenuChoice(scanner, 5); + + switch (choice) { + case 1 -> linkedListMenu(scanner); + case 2 -> stackMenu(scanner); + case 3 -> queueMenu(scanner); + case 4 -> treeMenu(scanner); + case 5 -> { + System.out.println("\nThank you for using Data Structure Demo!"); + running = false; + } } } } - scanner.close(); } /** * Displays the main menu options for selecting a data structure category or exiting the program. @@ -75,7 +74,7 @@ private static void displayMainMenu() { * * Loops until the user selects "Back to Main Menu". For each valid selection, invokes the corresponding linked list test and waits for the user to press Enter before showing the submenu again. */ - private static void linkedListMenu() { + private static void linkedListMenu(Scanner scanner) { while (true) { System.out.println("\n=== Linked List Types ==="); System.out.println("1. Simple Linked List"); @@ -86,7 +85,7 @@ private static void linkedListMenu() { System.out.println("6. Back to Main Menu"); System.out.print("\nEnter your choice (1-6): "); - int choice = getMenuChoice(6); + int choice = getMenuChoice(scanner, 6); if (choice == 6) break; System.out.println("\n=== Test Results ==="); @@ -97,7 +96,7 @@ private static void linkedListMenu() { case 4 -> testSortedLinkedList(); case 5 -> testDoublyEndedList(); } - pressEnterToContinue(); + pressEnterToContinue(scanner); } } @@ -106,7 +105,7 @@ private static void linkedListMenu() { * * Allows the user to choose between array-based and linked list-based stacks, runs the corresponding test demonstration, and returns to the main menu upon request. */ - private static void stackMenu() { + private static void stackMenu(Scanner scanner) { while (true) { System.out.println("\n=== Stack Types ==="); System.out.println("1. Array-based Stack"); @@ -114,7 +113,7 @@ private static void stackMenu() { System.out.println("3. Back to Main Menu"); System.out.print("\nEnter your choice (1-3): "); - int choice = getMenuChoice(3); + int choice = getMenuChoice(scanner, 3); if (choice == 3) break; System.out.println("\n=== Test Results ==="); @@ -122,7 +121,7 @@ private static void stackMenu() { case 1 -> testStackArray(); case 2 -> testStackLinkedList(); } - pressEnterToContinue(); + pressEnterToContinue(scanner); } } @@ -132,7 +131,7 @@ private static void stackMenu() { * Presents options for simple queue, array-based queue, linked list-based queue, and priority queue. * Executes the corresponding test method based on user selection and waits for user input before returning to the submenu. */ - private static void queueMenu() { + private static void queueMenu(Scanner scanner) { while (true) { System.out.println("\n=== Queue Types ==="); System.out.println("1. Simple Queue"); @@ -142,7 +141,7 @@ private static void queueMenu() { System.out.println("5. Back to Main Menu"); System.out.print("\nEnter your choice (1-5): "); - int choice = getMenuChoice(5); + int choice = getMenuChoice(scanner, 5); if (choice == 5) break; System.out.println("\n=== Test Results ==="); @@ -152,7 +151,7 @@ private static void queueMenu() { case 3 -> testQueueLinkedList(); case 4 -> testPriorityQueue(); } - pressEnterToContinue(); + pressEnterToContinue(scanner); } } @@ -161,21 +160,21 @@ private static void queueMenu() { * * Presents options for Binary Search Tree and AVL Tree, executes the corresponding test method based on user input, and waits for user confirmation before returning. */ - private static void treeMenu() { + private static void treeMenu(Scanner scanner) { System.out.println("\n=== Tree Types ==="); System.out.println("1. Binary Search Tree"); System.out.println("2. AVL Tree"); System.out.println("3. Back to Main Menu"); System.out.print("\nEnter your choice (1-3): "); - int choice = getMenuChoice(3); + int choice = getMenuChoice(scanner, 3); if (choice == 3) return; System.out.println("\n=== Test Results ==="); if (choice == 1) testBST(); else if (choice == 2) testAVL(); - pressEnterToContinue(); + pressEnterToContinue(scanner); } /** @@ -184,7 +183,7 @@ private static void treeMenu() { * @param max the maximum valid menu option (inclusive) * @return the user's validated menu choice as an integer between 1 and {@code max} */ - private static int getMenuChoice(int max) { + private static int getMenuChoice(Scanner scanner, int max) { while (true) { try { int choice = Integer.parseInt(scanner.nextLine().trim()); @@ -201,7 +200,7 @@ private static int getMenuChoice(int max) { /** * Prompts the user to press Enter and waits for input before continuing. */ - private static void pressEnterToContinue() { + private static void pressEnterToContinue(Scanner scanner) { System.out.print("\nPress Enter to continue..."); scanner.nextLine(); } diff --git a/src/main/java/org/dsa/common/Utils.java b/src/main/java/org/dsa/common/Utils.java index 0738908..d7733cc 100644 --- a/src/main/java/org/dsa/common/Utils.java +++ b/src/main/java/org/dsa/common/Utils.java @@ -11,13 +11,10 @@ public class Utils { * @return the array elements separated by the delimiter; an empty string if the array has no elements */ public static String intArrToStr(int[] arr, String delimiter) { - if (arr == null || delimiter == null) { - throw new IllegalArgumentException("Array and delimiter must not be null"); - } return Arrays.stream(arr) .mapToObj(String::valueOf) -- .reduce((a, b) -> a + delimiter + b) - .collect(java.util.stream.Collectors.joining(delimiter)); + .reduce((a, b) -> a + delimiter + b) + .orElse(""); } /** From 48381cf547d1404e137aa7de85ac1f5272b970f8 Mon Sep 17 00:00:00 2001 From: bcExpt1123 Date: Mon, 6 Oct 2025 14:16:09 +0530 Subject: [PATCH 19/22] Update workflows --- .github/workflows/label_pr.yaml | 2 +- .github/workflows/maven.yaml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/label_pr.yaml b/.github/workflows/label_pr.yaml index fb6aba9..c1e6c07 100644 --- a/.github/workflows/label_pr.yaml +++ b/.github/workflows/label_pr.yaml @@ -17,6 +17,6 @@ jobs: pull-requests: write steps: - - uses: actions/labeler@v4 + - uses: actions/labeler@v5 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml index 06b6aa0..15ade21 100644 --- a/.github/workflows/maven.yaml +++ b/.github/workflows/maven.yaml @@ -32,4 +32,5 @@ jobs: # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive - name: Update dependency graph + if: github.event_name == 'push' uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 From ab12e16aee469c5aa807e3a672a68e4a074ee03e Mon Sep 17 00:00:00 2001 From: bcExpt1123 Date: Mon, 6 Oct 2025 14:18:18 +0530 Subject: [PATCH 20/22] Update workflows --- .github/workflows/pmd.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yaml b/.github/workflows/pmd.yaml index 310b100..22f4573 100644 --- a/.github/workflows/pmd.yaml +++ b/.github/workflows/pmd.yaml @@ -30,7 +30,7 @@ jobs: distribution: 'temurin' - name: Run PMD id: pmd - uses: pmd/pmd-github-action@967a81f8b657c87f7c3e96b62301cb1a48efef29 + uses: pmd/pmd-github-action@v2 with: rulesets: 'rulesets/java/quickstart.xml' sourcePath: 'src/main/java' From 90b555b8d176cfe440593a5e4931c3a30c36f4b6 Mon Sep 17 00:00:00 2001 From: bcExpt1123 Date: Mon, 6 Oct 2025 14:20:39 +0530 Subject: [PATCH 21/22] Update workflows --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index deb495c..9f14d47 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.example - algo-datastructure + java-dsa 1.0-SNAPSHOT From f569726d328e55a251c83ea01b037af2c4c5e50c Mon Sep 17 00:00:00 2001 From: bcExpt1123 Date: Mon, 6 Oct 2025 14:22:19 +0530 Subject: [PATCH 22/22] Update workflows --- .github/workflows/maven.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml index 15ade21..2dc23ad 100644 --- a/.github/workflows/maven.yaml +++ b/.github/workflows/maven.yaml @@ -21,10 +21,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up JDK 17 + - name: Set up JDK 23 uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '23' distribution: 'temurin' cache: maven - name: Build with Maven