Various sites like this one use a pCrawl
variable to keep track of where a pointer is in the Trie data structure. I can see why the "crawl" part of the variable makes sense, if this means that the variable is "crawling" around the tree... but what does the p
refer to?
An example method: void insert(struct TrieNode *root, string key) { struct TrieNode *pCrawl = root;
for (int i = 0; i < key.length(); i++)
{
int index = key[i] - 'a';
if (!pCrawl->children[index])
pCrawl->children[index] = getNode();
pCrawl = pCrawl->children[index];
}
// mark last node as leaf
pCrawl->isEndOfWord = true;
}
Usually, in C
language, a lower case p
as a variable name prefix can be interpreted for pointer
. This is the case in the example you provided.
This is in no case an explicit rule, just a naming convention followed here and there.