Skip to content

Commit b657ae3

Browse files
authored
Remove main method and example usage
Removed main method and example usage from PatriciaTrie class.
1 parent 4e49696 commit b657ae3

File tree

1 file changed

+1
-31
lines changed

1 file changed

+1
-31
lines changed

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

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ public void insert(int key) {
158158

159159
// 4. Find the first bit position where the new key and its best match differ
160160
int differingBit = 1;
161-
// BUG FIX: The loop must check all bits (i <= MAX_BITS). The original
162-
// code (i < MAX_BITS) failed to check the last bit.
161+
// The loop must check all bits (i <= MAX_BITS).
163162
while (differingBit <= MAX_BITS && getBit(key, differingBit) == getBit(bestMatchNode.key, differingBit)) {
164163
differingBit++;
165164
}
@@ -197,33 +196,4 @@ public void insert(int key) {
197196
parent.leftChild = newNode;
198197
}
199198
}
200-
201-
// --- Main Driver and Example Usage ---
202-
203-
public static void main(String[] args) {
204-
PatriciaTrie trie = new PatriciaTrie();
205-
System.out.println("--- Patricia Trie Demonstration ---");
206-
System.out.println("Trie is empty: " + trie.isEmpty());
207-
208-
int[] keys = {10, 20, 15, 7, 5, 25};
209-
210-
System.out.println("\n--- Inserting Keys ---");
211-
for (int key : keys) {
212-
System.out.printf("Inserting: %3d (%s)%n", key, Integer.toBinaryString(key));
213-
trie.insert(key);
214-
}
215-
System.out.println("\nTrie is empty: " + trie.isEmpty());
216-
217-
System.out.println("\n--- Verifying Existing Keys ---");
218-
IntStream.of(keys).forEach(key -> System.out.printf("Search %3d: %s%n", key, trie.search(key) ? "Found" : "Not Found"));
219-
220-
System.out.println("\n--- Searching for Non-Existing Keys ---");
221-
System.out.printf("Search %3d: %s%n", 100, trie.search(100) ? "Found" : "Not Found");
222-
System.out.printf("Search %3d: %s%n", 0, trie.search(0) ? "Found" : "Not Found");
223-
224-
System.out.println("\n--- Attempting Duplicate Insertion ---");
225-
System.out.println("Inserting 20 again...");
226-
trie.insert(20); // Should do nothing
227-
System.out.printf("Search %3d: %s%n", 20, trie.search(20) ? "Found" : "Not Found");
228-
}
229199
}

0 commit comments

Comments
 (0)