Skip to content

Commit 8b1569c

Browse files
authored
Merge pull request #4 from bcExpt1123/coderabbitai/docstrings/9534874
📝 Add docstrings to `test`
2 parents 9534874 + 7ac7f51 commit 8b1569c

File tree

10 files changed

+136
-15
lines changed

10 files changed

+136
-15
lines changed

src/main/java/org/alda/Main.java

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
public class Main {
3333
private static final Scanner scanner = new Scanner(System.in);
3434

35+
/**
36+
* Launches the interactive console application for demonstrating various data structures.
37+
*
38+
* 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.
39+
*
40+
* @param args command-line arguments (not used)
41+
*/
3542
public static void main(String[] args) {
3643
boolean running = true;
3744

@@ -52,6 +59,9 @@ public static void main(String[] args) {
5259
}
5360
scanner.close();
5461
}
62+
/**
63+
* Displays the main menu options for selecting a data structure category or exiting the program.
64+
*/
5565
private static void displayMainMenu() {
5666
System.out.println("\n=== Data Structure Demonstration ===");
5767
System.out.println("1. Linked Lists");
@@ -62,6 +72,11 @@ private static void displayMainMenu() {
6272
System.out.print("\nEnter your choice (1-5): ");
6373
}
6474

75+
/**
76+
* Displays a submenu for selecting and testing different types of linked lists.
77+
*
78+
* 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.
79+
*/
6580
private static void linkedListMenu() {
6681
while (true) {
6782
System.out.println("\n=== Linked List Types ===");
@@ -88,6 +103,11 @@ private static void linkedListMenu() {
88103
}
89104
}
90105

106+
/**
107+
* Displays an interactive submenu for selecting and testing different stack implementations.
108+
*
109+
* 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.
110+
*/
91111
private static void stackMenu() {
92112
while (true) {
93113
System.out.println("\n=== Stack Types ===");
@@ -108,6 +128,12 @@ private static void stackMenu() {
108128
}
109129
}
110130

131+
/**
132+
* Displays an interactive submenu for selecting and testing different queue implementations.
133+
*
134+
* Presents options for simple queue, array-based queue, linked list-based queue, and priority queue.
135+
* Executes the corresponding test method based on user selection and waits for user input before returning to the submenu.
136+
*/
111137
private static void queueMenu() {
112138
while (true) {
113139
System.out.println("\n=== Queue Types ===");
@@ -132,6 +158,11 @@ private static void queueMenu() {
132158
}
133159
}
134160

161+
/**
162+
* Displays a submenu for tree data structure demonstrations and runs the selected test.
163+
*
164+
* 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.
165+
*/
135166
private static void treeMenu() {
136167
System.out.println("\n=== Tree Types ===");
137168
System.out.println("1. Binary Search Tree");
@@ -149,6 +180,12 @@ private static void treeMenu() {
149180
pressEnterToContinue();
150181
}
151182

183+
/**
184+
* Prompts the user to enter a menu choice and returns a valid integer within the specified range.
185+
*
186+
* @param max the maximum valid menu option (inclusive)
187+
* @return the user's validated menu choice as an integer between 1 and {@code max}
188+
*/
152189
private static int getMenuChoice(int max) {
153190
while (true) {
154191
try {
@@ -163,11 +200,19 @@ private static int getMenuChoice(int max) {
163200
}
164201
}
165202

203+
/**
204+
* Prompts the user to press Enter and waits for input before continuing.
205+
*/
166206
private static void pressEnterToContinue() {
167207
System.out.print("\nPress Enter to continue...");
168208
scanner.nextLine();
169209
}
170210

211+
/**
212+
* Demonstrates basic operations on a simple linked list of integers, including appending, inserting, deleting, printing, and searching for elements.
213+
*
214+
* Initializes a simple linked list, performs a sequence of modifications, prints the list and head node, and displays search results for specific values.
215+
*/
171216
public static void testSimpleLinkedList() {
172217
System.out.println("\n=== Initialize Simple Linked List ===");
173218
ISimpleLinkedList<Integer> intList = new SimpleLinkedList<Integer>();
@@ -195,6 +240,11 @@ public static void testSimpleLinkedList() {
195240
System.out.println("Search for 5: " + intList.search(5));
196241
}
197242

243+
/**
244+
* Demonstrates basic operations on a doubly linked list of integers.
245+
*
246+
* Initializes a doubly linked list, appends several integer values, and prints the list in forward order.
247+
*/
198248
public static void testDoublyLinkedList() {
199249
System.out.println("\n=== Initialize Doubly Linked List ===");
200250
DoublyLinkedList<Integer> intList = new DoublyLinkedList<Integer>();
@@ -209,6 +259,11 @@ public static void testDoublyLinkedList() {
209259
intList.print();
210260
}
211261

262+
/**
263+
* Demonstrates basic operations on a circular linked list of integers.
264+
*
265+
* Initializes a circular linked list, appends several integer values, and prints the list contents.
266+
*/
212267
public static void testCircularLinkedList() {
213268
System.out.println("\n=== Initialize Circular Linked List ===");
214269
CircularLinkedList<Integer> intList = new CircularLinkedList<Integer>();
@@ -223,6 +278,11 @@ public static void testCircularLinkedList() {
223278
intList.print();
224279
}
225280

281+
/**
282+
* Demonstrates the usage of a sorted linked list by inserting integers in non-sorted order and printing the sorted result.
283+
*
284+
* Initializes a sorted linked list, inserts several integer values using sorted insertion, and prints the list to show the maintained order.
285+
*/
226286
public static void testSortedLinkedList() {
227287
System.out.println("\n=== Initialize Sorted Linked List ===");
228288
ISortedLinkedList<Integer> intList = new SortedLinkedList<Integer>();
@@ -238,6 +298,11 @@ public static void testSortedLinkedList() {
238298
intList.print();
239299
}
240300

301+
/**
302+
* Demonstrates basic operations on a doubly ended linked list (deque) of integers.
303+
*
304+
* Initializes a doubly ended list, performs a sequence of insertions at both the front and end, and prints the resulting list.
305+
*/
241306
public static void testDoublyEndedList(){
242307
System.out.println("\n=== Initialize Doubly Ended Linked List ===");
243308
IDoublyEndedList<Integer> intList = new DoublyEndedList<>();
@@ -255,6 +320,11 @@ public static void testDoublyEndedList(){
255320
intList.print();
256321
}
257322

323+
/**
324+
* Demonstrates basic operations on an array-based stack of integers.
325+
*
326+
* Initializes a stack, pushes several values, then performs pop and peek operations while printing the results.
327+
*/
258328
public static void testStackArray(){
259329
System.out.println("\n=== Initialize Stack Array ===");
260330
IStackArray<Integer> intStack = new StackArray<>();
@@ -269,6 +339,11 @@ public static void testStackArray(){
269339
System.out.println("Pop: " + intStack.pop());
270340
}
271341

342+
/**
343+
* Demonstrates stack operations using a linked list implementation.
344+
*
345+
* Initializes a linked list-based stack, performs push, pop, and peek operations, and prints the results to the console.
346+
*/
272347
public static void testStackLinkedList(){
273348
System.out.println("\n=== Initialize Stack Linked List ===");
274349
IStackLinkedList<Integer> intStack = new StackLinkedList<>();
@@ -283,6 +358,11 @@ public static void testStackLinkedList(){
283358
System.out.println("Pop: " + intStack.pop());
284359
}
285360

361+
/**
362+
* Demonstrates basic queue operations including enqueue, dequeue, and retrieving front and rear elements.
363+
*
364+
* Initializes a queue of integers, enqueues several values, dequeues three elements, and prints the results along with the current front and rear values.
365+
*/
286366
public static void testQueue(){
287367
System.out.println("\n=== Initialize Queue ===");
288368
IQueue<Integer> intQueue = new Queue<>();
@@ -308,6 +388,11 @@ public static void testQueue(){
308388
System.out.println("Rear: " + rear);
309389
}
310390

391+
/**
392+
* Demonstrates the usage of an array-based queue by performing enqueue, dequeue, and inspection operations.
393+
*
394+
* Initializes an integer queue, enqueues several elements, dequeues three elements, and prints the dequeued values along with the current front and rear elements.
395+
*/
311396
public static void testQueueArray(){
312397
System.out.println("\n=== Initialize Queue Array ===");
313398
IQueue<Integer> intQueue = new QueueArray<>();
@@ -333,6 +418,11 @@ public static void testQueueArray(){
333418
System.out.println("Rear: " + rear);
334419
}
335420

421+
/**
422+
* Demonstrates the usage of a linked list-based queue by performing enqueue, dequeue, and inspection operations.
423+
*
424+
* Initializes a queue, enqueues several integers, dequeues multiple elements, and prints the results along with the current front and rear elements.
425+
*/
336426
public static void testQueueLinkedList(){
337427
System.out.println("\n=== Initialize Queue Linked List ===");
338428
IQueue<Integer> intQueue = new QueueLinkedList<>();
@@ -358,6 +448,11 @@ public static void testQueueLinkedList(){
358448
System.out.println("Rear: " + rear);
359449
}
360450

451+
/**
452+
* Demonstrates the usage of a priority queue by enqueuing integer elements with specified priorities and dequeuing several elements to show priority-based removal order.
453+
*
454+
* 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.
455+
*/
361456
public static void testPriorityQueue(){
362457
System.out.println("\n=== Initialize Priority Queue ===");
363458
IPriorityQueue<Integer> intQueue = new PriorityQueue<>();
@@ -386,6 +481,12 @@ public static void testPriorityQueue(){
386481
System.out.println("Dequeue: " + item3);
387482
}
388483

484+
/**
485+
* Demonstrates basic operations on a binary search tree, including insertion, inorder traversal, and search.
486+
*
487+
* Initializes a binary search tree of integers, inserts several values, prints the inorder traversal,
488+
* and searches for the value 4, displaying whether it is found.
489+
*/
389490
public static void testBST(){
390491
System.out.println("\n=== Initialize Binary Search Tree ===");
391492
BinarySearchTree<Integer> bst = new BinarySearchTree<>();
@@ -406,6 +507,11 @@ public static void testBST(){
406507
else System.out.println("false");
407508
}
408509

510+
/**
511+
* Demonstrates insertion of multiple integers into an AVL tree.
512+
*
513+
* Initializes an AVL tree and inserts the values 10, 20, 30, 40, 50, and 25 to showcase automatic balancing during insertion.
514+
*/
409515
public static void testAVL(){
410516
AVL<Integer> avl = new AVL<>();
411517
AVL.Node<Integer> root = null;

src/main/java/org/alda/structure/linkedList/circular/CircularLinkedList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public void append(T data) {
6363
}
6464

6565
/**
66-
* Prints the data stored in each node of the circular linked list.
67-
* The traversal stops when the list has looped back to the head.
66+
* Prints the data of each node in the circular linked list in sequence, starting from the head.
67+
* Traversal continues until the list loops back to the head node or if the list is empty.
6868
*/
6969
public void print() {
7070
Node<T> current = head;

src/main/java/org/alda/structure/linkedList/circular/Node.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ public Node(T data) {
4949
}
5050

5151
/**
52-
* Prints the data stored in this node and, if present, the data in the next node.
53-
* The output format is: {@code Data: <data>, Next: <next data>}
52+
* Prints this node's data and, if available, the data of the next node to standard output.
53+
*
54+
* The output begins with a newline and follows the format: {@code Data: <data>, Next: <next data>}.
5455
*/
5556
public void print() {
5657
System.out.print("\nData: " + data);

src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ public void setTail(Node<T> tail) {
6868
}
6969

7070
/**
71-
* Prints the contents of the list.
72-
* Each node's data is printed, followed by a new line.
71+
* Prints the data of each node in the list from head to tail.
7372
*/
7473
public void print() {
7574
Node<T> current = head;

src/main/java/org/alda/structure/linkedList/deque/Node.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ public Node(){
5252
}
5353

5454
/**
55-
* Prints the data stored in this node, and if present, the data in the next and previous nodes.
56-
* The output format is: {@code Data: <data>, Next: <next data>, Prev: <previous data>}
55+
* Prints this node's data, along with the data of adjacent nodes if available, to standard output.
56+
*
57+
* The output includes the node's data, and, if present, the data of the next and previous nodes in the format:
58+
* {@code Data: <data>, Next: <next data>, Prev: <previous data>}.
5759
*/
5860
public void print(){
5961
System.out.print("\nData: " + data);

src/main/java/org/alda/structure/linkedList/doubly/DoublyLinkedList.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ public void prepend(T data) {
7878
}
7979

8080
/**
81-
* Prints the data stored in each node of the doubly linked list from head to tail.
82-
* Each node's data is printed along with the data in its next and previous nodes, if available.
81+
* Prints each node's data in the list from head to tail, including adjacent nodes' data if present.
8382
*/
8483
public void print() {
8584
Node<T> current = head;

src/main/java/org/alda/structure/linkedList/doubly/Node.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ public Node(final T data) {
4444
}
4545

4646
/**
47-
* Prints the data stored in this node, as well as the data in the next and previous nodes, if available.
48-
* The output format is: {@code Data: <data>, Next: <next data>, Prev: <prev data>}
47+
* Prints this node's data, along with the data of adjacent nodes if they exist.
48+
*
49+
* The output begins with a newline and follows the format:
50+
* {@code Data: <data>, Next: <next data>, Prev: <prev data>}.
51+
* The "Next" and "Prev" fields are included only if the corresponding nodes are present.
4952
*/
5053
public void print() {
5154
System.out.print("\nData: " + data);

src/main/java/org/alda/structure/linkedList/simple/Node.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ public Node(T data) {
3737
}
3838

3939
/**
40-
* Prints the data stored in this node and, if present, the data in the next node.
41-
* The output format is: {@code Data: <data>, Next: <next data>}
40+
* Prints the data of this node, and if a next node exists, also prints its data.
41+
*
42+
* The output is formatted as: {@code Data: <data>, Next: <next data>}, with a preceding newline.
4243
*/
4344
public void print() {
4445
System.out.print("\nData: " + data);

src/main/java/org/alda/structure/linkedList/simple/SimpleLinkedList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void setHead(Node<T> head) {
136136
}
137137

138138
/**
139-
* Prints the data stored in each node of the linked list from head to tail.
139+
* Outputs the data of each node in the linked list sequentially from head to tail.
140140
*/
141141
public void print() {
142142
Node<T> current = head;

src/main/java/org/alda/structure/tree/bst/Node.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,22 @@ public class Node<T> implements Printable {
1010
T key;
1111
Node<T> left;
1212
Node<T> right;
13+
/**
14+
* Constructs a new node with the specified key and no child nodes.
15+
*
16+
* @param key the value to store in this node
17+
*/
1318
public Node(T key){
1419
this.key = key;
1520
left = null;
1621
right = null;
1722
}
1823

24+
/**
25+
* Prints the node's key and the keys of its left and right children, if present, to the standard output.
26+
*
27+
* The output format is: "Data: [key], Left: [left.key], Right: [right.key]". Child information is omitted if the respective child is null.
28+
*/
1929
public void print() {
2030
System.out.print("\nData: " + key);
2131
if (left != null) {

0 commit comments

Comments
 (0)