Skip to content

Commit 8f7881b

Browse files
committed
Fix clang errors
1 parent 8ad75ba commit 8f7881b

File tree

1 file changed

+47
-48
lines changed
  • src/main/java/com/thealgorithms/datastructures/trees

1 file changed

+47
-48
lines changed

src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java

+47-48
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public TrieImp() {
5757
* The method traverses the Trie from the root, character by character, and adds
5858
* nodes
5959
* if necessary. It marks the last node of the word as an end node.
60-
*
60+
*
6161
* @param word The word to be inserted into the Trie.
6262
*/
6363
public void insert(String word) {
@@ -81,7 +81,7 @@ public void insert(String word) {
8181
* This method traverses the Trie based on the input word and checks whether
8282
* the word exists. It returns true if the word is found and its end flag is
8383
* true.
84-
*
84+
*
8585
* @param word The word to search in the Trie.
8686
* @return true if the word exists in the Trie, false otherwise.
8787
*/
@@ -105,7 +105,7 @@ public boolean search(String word) {
105105
* false.
106106
* It returns true if the word was successfully deleted, false if the word
107107
* wasn't found.
108-
*
108+
*
109109
* @param word The word to be deleted from the Trie.
110110
* @return true if the word was found and deleted, false if it was not found.
111111
*/
@@ -129,7 +129,7 @@ public boolean delete(String word) {
129129

130130
/**
131131
* Helper method to print a string to the console.
132-
*
132+
*
133133
* @param print The string to be printed.
134134
*/
135135
public static void sop(String print) {
@@ -142,7 +142,7 @@ public static void sop(String print) {
142142
* <p>
143143
* The method uses a regular expression to check if the word matches the pattern
144144
* of only lowercase letters.
145-
*
145+
*
146146
* @param word The word to be validated.
147147
* @return true if the word is valid (only a-z), false otherwise.
148148
*/
@@ -156,14 +156,13 @@ public static boolean isValid(String word) {
156156
* The user can choose between inserting a word, searching for a word,
157157
* deleting a word, or quitting the program. It uses a loop to continuously
158158
* ask for user input until the program is quit.
159-
*
159+
*
160160
* @param args Command-line arguments (not used in this program).
161161
*/
162162
public static void main(String[] args) {
163163
TrieImp obj = new TrieImp();
164164
String word;
165-
@SuppressWarnings("resource")
166-
Scanner scan = new Scanner(System.in);
165+
@SuppressWarnings("resource") Scanner scan = new Scanner(System.in);
167166

168167
sop("string should contain only a-z character for all operation");
169168

@@ -173,46 +172,46 @@ public static void main(String[] args) {
173172
try {
174173
int t = scan.nextInt();
175174
switch (t) {
176-
case 1:
177-
// Insert a word into the Trie
178-
word = scan.next();
179-
if (isValid(word)) {
180-
obj.insert(word);
181-
sop("Word inserted successfully");
182-
} else {
183-
sop("Invalid string: allowed only a-z");
184-
}
185-
break;
186-
case 2:
187-
// Search for a word in the Trie
188-
word = scan.next();
189-
boolean resS = false;
190-
if (isValid(word)) {
191-
resS = obj.search(word);
192-
} else {
193-
sop("Invalid string: allowed only a-z");
194-
}
195-
sop(resS ? "Word found" : "Word not found");
196-
break;
197-
case 3:
198-
// Delete a word from the Trie
199-
word = scan.next();
200-
boolean resD = false;
201-
if (isValid(word)) {
202-
resD = obj.delete(word);
203-
} else {
204-
sop("Invalid string: allowed only a-z");
205-
}
206-
sop(resD ? "Word deleted successfully" : "Word not found");
207-
break;
208-
case 4:
209-
// Quit the program
210-
sop("Quit successfully");
211-
System.exit(1);
212-
break;
213-
default:
214-
sop("Input int from 1-4");
215-
break;
175+
case 1:
176+
// Insert a word into the Trie
177+
word = scan.next();
178+
if (isValid(word)) {
179+
obj.insert(word);
180+
sop("Word inserted successfully");
181+
} else {
182+
sop("Invalid string: allowed only a-z");
183+
}
184+
break;
185+
case 2:
186+
// Search for a word in the Trie
187+
word = scan.next();
188+
boolean resS = false;
189+
if (isValid(word)) {
190+
resS = obj.search(word);
191+
} else {
192+
sop("Invalid string: allowed only a-z");
193+
}
194+
sop(resS ? "Word found" : "Word not found");
195+
break;
196+
case 3:
197+
// Delete a word from the Trie
198+
word = scan.next();
199+
boolean resD = false;
200+
if (isValid(word)) {
201+
resD = obj.delete(word);
202+
} else {
203+
sop("Invalid string: allowed only a-z");
204+
}
205+
sop(resD ? "Word deleted successfully" : "Word not found");
206+
break;
207+
case 4:
208+
// Quit the program
209+
sop("Quit successfully");
210+
System.exit(1);
211+
break;
212+
default:
213+
sop("Input int from 1-4");
214+
break;
216215
}
217216
} catch (Exception e) {
218217
// Handle bad input

0 commit comments

Comments
 (0)