int deleteHelper(trieNode_t *pNode, char key[], int level, int len) { if( pNode ) { // Base case if( level == len ) { if( pNode->eos ) { // Unmark leaf node pNode->eos = 0; // If empty, node to be deleted if( isItFreeNode(pNode) ) { return 1; } return 0; } } else // Recursive case { int index = key[level]-'a'; if( deleteHelper(pNode->child[index], key, level+1, len) ) { // last node marked, delete it FREE(pNode->child[index]); // recursively climb up, and delete eligible nodes return ( !leafNode(pNode) && isItFreeNode(pNode) ); } } } return 0; }
bool deleteHelper(trie_node_t *pNode, char key[], int level, int len) { if( pNode ) { // Base case if( level == len ) { if( pNode->value ) { // Unmark leaf node pNode->value = 0; // If empty, node to be deleted if( isItFreeNode(pNode) ) { return true; } return false; } } else // Recursive case { int index = INDEX(key[level]); if( deleteHelper(pNode->children[index], key, level+1, len) ) { // last node marked, delete it FREE(pNode->children[index]); // recursively climb up, and delete eligible nodes return ( !leafNode(pNode) && isItFreeNode(pNode) ); } } } return false; }