TRIE DATA STRUCTURES
Can anybody please help me verify my code. I tried writing this code and it works properly, since I am new to this coding, I am not having confidence that I have written the correct logic and I am dependent on others to check whether I am right. Thank you in advance. public class TrieNode { HashMap<Character, TrieNode> map = new HashMap<Character, TrieNode>(); TrieNode root; TrieNode temp; public TrieNode() { this.root = null; } String End = "N"; public void insert(String element) { TrieNode node = new TrieNode(); if (root == null) { root = node; } else { node = root; } for (int i = 0; i <= element.length(); i++) { if (i < element.length()) { if (!node.map.containsKey(element.charAt(i))) { temp = new TrieNode(); node.map.put(element.charAt(i), temp); node = temp; } else { node = node.map.get(element.charAt(i)); } } else { node.End = "Y"; } } } public boolean search(String element) { TrieNode node = new TrieNode(); node = root; if (root == null) { System.out.println("Trie empty"); return false; } else { for (int i = 0; i <= element.length(); i++) { if (i < element.length() && node.map.containsKey(element.charAt(i))) { node = node.map.get(element.charAt(i)); } else if (i == element.length() && node.End == "Y") { System.out.println("Word found"); return true; } else { System.out.println("Word not found"); return false; } } return true; } } }