Skip to content

Commit a000fdd

Browse files
committed
Merge conflicts
2 parents 38b6103 + 8b1569c commit a000fdd

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
@@ -33,6 +33,13 @@
3333
public class Main {
3434
private static final Scanner scanner = new Scanner(System.in);
3535

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

511+
/**
512+
* Demonstrates insertion of multiple integers into an AVL tree.
513+
*
514+
* Initializes an AVL tree and inserts the values 10, 20, 30, 40, 50, and 25 to showcase automatic balancing during insertion.
515+
*/
410516
public static void testAVL(){
411517
AVLTest.main(null);
412518
}

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)