Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0cab126
Add Command Pattern to create an interactive menu system in Main.java
bcExpt1123 Jun 25, 2025
9534874
Update test results
bcExpt1123 Jun 25, 2025
7ac7f51
📝 Add docstrings to `test`
coderabbitai[bot] Jun 25, 2025
8b1569c
Merge pull request #4 from bcExpt1123/coderabbitai/docstrings/9534874
bcExpt1123 Jun 25, 2025
38b6103
Add AVL tests
bcExpt1123 Jun 26, 2025
a000fdd
Merge conflicts
bcExpt1123 Jun 26, 2025
ce41903
Add Style checker
bcExpt1123 Jun 26, 2025
bc46e24
Create summarize_new_issue.yaml
bcExpt1123 Jun 26, 2025
b112a6b
Create label_pr.yaml
bcExpt1123 Jun 26, 2025
00b8e62
Create maven.yaml
bcExpt1123 Jun 26, 2025
d4386b7
Create pmd.yaml
bcExpt1123 Jun 26, 2025
6cd75ef
Create codeql
bcExpt1123 Jun 26, 2025
3f456f5
Rename codeql to codeql.yaml
bcExpt1123 Jun 26, 2025
d8c6135
Update label_pr.yaml
bcExpt1123 Jun 26, 2025
39b1929
📝 Add docstrings to `test`
coderabbitai[bot] Oct 2, 2025
f0f793d
Merge pull request #6 from bcExpt1123/coderabbitai/docstrings/ce41903
bcExpt1123 Oct 2, 2025
59d5b55
Rename package
bcExpt1123 Oct 6, 2025
abcce9b
Update summarize new issue workflwo
bcExpt1123 Oct 6, 2025
9c61236
Update .github/workflows/summarize_new_issue.yaml
bcExpt1123 Oct 6, 2025
16e4b2e
Merge pull request #5 from bcExpt1123/workflows
bcExpt1123 Oct 6, 2025
ba286a2
Update src/main/java/org/dsa/common/Utils.java
bcExpt1123 Oct 6, 2025
a64306d
Update Main.java - scanner, and revert Utils
bcExpt1123 Oct 6, 2025
48381cf
Update workflows
bcExpt1123 Oct 6, 2025
ab12e16
Update workflows
bcExpt1123 Oct 6, 2025
90b555b
Update workflows
bcExpt1123 Oct 6, 2025
f569726
Update workflows
bcExpt1123 Oct 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
361 changes: 322 additions & 39 deletions src/main/java/org/alda/Main.java

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/main/java/org/alda/common/Utils.java
Original file line number Diff line number Diff line change
@@ -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, ", ");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ 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<T> current = head;
while (current != null) {
current.print();
System.out.println("\n");
current = current.next;
if(current == head) {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ 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: <data>, Next: <next data>}
* 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: <data>, Next: <next data>}.
*/
public void print() {
System.out.print("Data: " + data);
System.out.print("\nData: " + data);
if (next != null) {
System.out.print(", Next: " + next.data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ public void setTail(Node<T> 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<T> current = head;
while (current != null) {
current.print();
System.out.println("\n");
current = current.next;
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/org/alda/structure/linkedList/deque/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ 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: <data>, Next: <next data>, Prev: <previous data>}
* 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: <data>, Next: <next data>, Prev: <previous data>}.
*/
public void print(){
System.out.print("Data: " + data);
System.out.print("\nData: " + data);
if (next != null) {
System.out.print(", Next: " + next.data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,12 @@ 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<T> current = head;
while (current != null) {
current.print();
System.out.println("\n");
current = current.next;
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/org/alda/structure/linkedList/doubly/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ 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: <data>, Next: <next data>, Prev: <prev data>}
* 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: <data>, Next: <next data>, Prev: <prev data>}.
* The "Next" and "Prev" fields are included only if the corresponding nodes are present.
*/
public void print() {
System.out.print("Data: " + data);
System.out.print("\nData: " + data);
if (next != null) {
System.out.print(", Next: " + next.data);
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/alda/structure/linkedList/simple/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ 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: <data>, Next: <next data>}
* Prints the data of this node, and if a next node exists, also prints its data.
*
* The output is formatted as: {@code Data: <data>, Next: <next data>}, with a preceding newline.
*/
public void print() {
System.out.print("Data: " + data);
System.out.print("\nData: " + data);
if(next != null) {
System.out.print(", Next: " + next.data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,12 @@ public void setHead(Node<T> 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<T> current = head;
while (current != null) {
current.print();
System.out.println("\n");
current = current.next;
}
}
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/org/alda/structure/tree/bst/Node.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
package org.alda.structure.tree.bst;

import org.alda.common.Printable;

/**
* Node for binary search tree
* @param <T>
*/
public class Node<T> {
public class Node<T> implements Printable {
T key;
Node<T> left;
Node<T> 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) {
System.out.print(", Left: " + left.key);
}
if (right != null) {
System.out.print(", Right: " + right.key);
}
}
}
8 changes: 5 additions & 3 deletions src/main/java/org/alda/structure/tree/bst/bbt/AVL.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public Node<T> insert(Node<T> 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));
Expand Down Expand Up @@ -73,8 +75,8 @@ public Integer getHeight(Node<T> root) {
}

public Integer getBalance(Node<T> 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<T> rotateRight(Node<T> z) {
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/org/alda/structure/tree/bst/bbt/AVLTest.java
Original file line number Diff line number Diff line change
@@ -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<Integer> avl = new AVL<>();
AVL.Node<Integer> 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 <T extends Comparable<T>> void inOrder(AVL.Node<T> node) {
if (node != null) {
inOrder(node.left);
System.out.print(node.key + " ");
inOrder(node.right);
}
}

// Pretty-print the tree
public static <T extends Comparable<T>> void printTree(AVL.Node<T> 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);
}
}
}
42 changes: 42 additions & 0 deletions src/test/java/org/alda/common/UtilsTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}