You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* 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
+
*/
35
42
publicstaticvoidmain(String[] args) {
36
43
booleanrunning = true;
37
44
@@ -52,6 +59,9 @@ public static void main(String[] args) {
52
59
}
53
60
scanner.close();
54
61
}
62
+
/**
63
+
* Displays the main menu options for selecting a data structure category or exiting the program.
64
+
*/
55
65
privatestaticvoiddisplayMainMenu() {
56
66
System.out.println("\n=== Data Structure Demonstration ===");
* 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
+
*/
65
80
privatestaticvoidlinkedListMenu() {
66
81
while (true) {
67
82
System.out.println("\n=== Linked List Types ===");
* 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.
* 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.
* 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
+
*/
152
189
privatestaticintgetMenuChoice(intmax) {
153
190
while (true) {
154
191
try {
@@ -163,11 +200,19 @@ private static int getMenuChoice(int max) {
163
200
}
164
201
}
165
202
203
+
/**
204
+
* Prompts the user to press Enter and waits for input before continuing.
205
+
*/
166
206
privatestaticvoidpressEnterToContinue() {
167
207
System.out.print("\nPress Enter to continue...");
168
208
scanner.nextLine();
169
209
}
170
210
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
+
*/
171
216
publicstaticvoidtestSimpleLinkedList() {
172
217
System.out.println("\n=== Initialize Simple Linked List ===");
@@ -283,6 +358,11 @@ public static void testStackLinkedList(){
283
358
System.out.println("Pop: " + intStack.pop());
284
359
}
285
360
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
+
*/
286
366
publicstaticvoidtestQueue(){
287
367
System.out.println("\n=== Initialize Queue ===");
288
368
IQueue<Integer> intQueue = newQueue<>();
@@ -308,6 +388,11 @@ public static void testQueue(){
308
388
System.out.println("Rear: " + rear);
309
389
}
310
390
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.
@@ -358,6 +448,11 @@ public static void testQueueLinkedList(){
358
448
System.out.println("Rear: " + rear);
359
449
}
360
450
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.
0 commit comments