解除分配指针我试图要解除我的线索指针。 这里是我的特里结构对特里
struct trie
{
int x;
trie *next[26];
};
trie *head;
trie *tmp;
,这里是使用DFS
void deallocate(trie *cur)
{
for (int a=0; a<=25; a++)
{
if (cur->next[a] != NULL)
{
tmp = cur->next[a];
cur->next[a] = NULL;
deallocate(tmp);
}
}
free(cur);
}
,这里是我的头初始化函数
void init()
{
head = new trie;
head->x = 0;
for (int a=0; a<=25; a++)
{
head->next[a] = NULL;
}
}
和程序我叫deallocate(head);
结束后,我解除分配功能
我真正的新指针东西,我的deallocate函数有什么不对吗?感谢
改变数组的大小和被录取了:)看来问题不是指针:)感谢大家
什么是'FOR'? – piokuc
@piokuc它可能是一个扩展为'for int a = 0的宏;一个<25; ++ a)' – ChrisW
它真的是一个C++问题吗?似乎更像C. – StoryTeller