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.
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
+
*/
36
43
publicstaticvoidmain(String[] args) {
37
44
booleanrunning = true;
38
45
@@ -53,6 +60,9 @@ public static void main(String[] args) {
53
60
}
54
61
scanner.close();
55
62
}
63
+
/**
64
+
* Displays the main menu options for selecting a data structure category or exiting the program.
65
+
*/
56
66
privatestaticvoiddisplayMainMenu() {
57
67
System.out.println("\n=== Data Structure Demonstration ===");
* 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
+
*/
66
81
privatestaticvoidlinkedListMenu() {
67
82
while (true) {
68
83
System.out.println("\n=== Linked List Types ===");
* 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.
* 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.
* 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
+
*/
153
190
privatestaticintgetMenuChoice(intmax) {
154
191
while (true) {
155
192
try {
@@ -164,11 +201,19 @@ private static int getMenuChoice(int max) {
164
201
}
165
202
}
166
203
204
+
/**
205
+
* Prompts the user to press Enter and waits for input before continuing.
206
+
*/
167
207
privatestaticvoidpressEnterToContinue() {
168
208
System.out.print("\nPress Enter to continue...");
169
209
scanner.nextLine();
170
210
}
171
211
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
+
*/
172
217
publicstaticvoidtestSimpleLinkedList() {
173
218
System.out.println("\n=== Initialize Simple Linked List ===");
@@ -284,6 +359,11 @@ public static void testStackLinkedList(){
284
359
System.out.println("Pop: " + intStack.pop());
285
360
}
286
361
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
+
*/
287
367
publicstaticvoidtestQueue(){
288
368
System.out.println("\n=== Initialize Queue ===");
289
369
IQueue<Integer> intQueue = newQueue<>();
@@ -309,6 +389,11 @@ public static void testQueue(){
309
389
System.out.println("Rear: " + rear);
310
390
}
311
391
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.
@@ -359,6 +449,11 @@ public static void testQueueLinkedList(){
359
449
System.out.println("Rear: " + rear);
360
450
}
361
451
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.
0 commit comments