-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMenu.java
More file actions
76 lines (69 loc) · 2.74 KB
/
Copy pathMenu.java
File metadata and controls
76 lines (69 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.text.Normalizer;
import java.util.InputMismatchException;
import java.util.Scanner;
public class Menu {
private AVL avlTree;
public Menu(AVL avlTree) {
this.avlTree = avlTree;
}
public void display() {
Scanner scanner = new Scanner(System.in);
int choice = 0;
do {
System.out.println("Menu:");
System.out.println("1. Print Pre-Order");
System.out.println("2. Print In-Order");
System.out.println("3. Print Post-Order");
System.out.println("4. Search for a word");
System.out.println("0. Exit");
System.out.print("Choose an option: ");
try{
choice = scanner.nextInt();
scanner.nextLine();
}
catch(InputMismatchException exception){
System.out.println("Type a valid option: ");
break;
}
switch (choice) {
case 1:
System.out.println("Pre-Order Traversal:");
avlTree.printPreOrder(avlTree.getRoot());
System.out.println("==============================");
break;
case 2:
System.out.println("In-Order Traversal:");
avlTree.printInOrder(avlTree.getRoot());
System.out.println("==============================");
break;
case 3:
System.out.println("Post-Order Traversal:");
avlTree.printPostOrder(avlTree.getRoot());
System.out.println("==============================");
break;
case 4:
System.out.print("Enter the word to search: ");
String word = scanner.nextLine();
word = word.replaceAll("\\p{Punct}", "");
word = removerAcentos(word);
if (avlTree.elementExists(avlTree.getRoot(), word, 1) != null) {
System.out.println("Word found.");
} else {
System.out.println("Word not found.");
}
break;
case 0:
System.out.println("Exiting...");
break;
default:
System.out.println("Invalid option. Please try again.");
break;
}
} while (choice != 0);
scanner.close();
}
public static String removerAcentos(String palavra) {
String normalized = Normalizer.normalize(palavra, Normalizer.Form.NFD);
return normalized.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
}
}