트라이
-
트라이, 아호 코라식Problem Solving 2024. 8. 11. 13:56
트라이문자열 집합을 트리 형태로 저장하는 자료구조다.각 노드에 26개의 알파벳 노드를 배열로 저장한다. int toNumber(char ch) { return ch - ‘A’; }struct TrieNode { TrieNode* children[26]; bool terminal; TrieNode() : terminal(false) { memset(children, 0, sizeof(children)); } ~TrieNode() { // destructor 소멸자 for(int i=0; i insert(key + 1); // key+1은 내 다음 문자의 포인터 가르킴 } } TrieNode* find(const char* key) { // ke..