我正在尝试在 C++中实现尝试。这是我使用的结构:
typedef struct tries{
int wordCount;
int prefixCount;
map<int,struct tries*> children;
}tries;
初始化方法:
void initialise(tries *vertex)
{
vertex = (tries*)malloc(sizeof(tries*));
vertex->wordCount = vertex->prefixCount = 0;
for(char ch='a';ch<='z';ch++)
vertex->children[ch]=NULL;
}
初始化方法有分段错误在vertex->children[ch]=NULL;
错误是:
Program received signal SIGSEGV, Segmentation fault.
0x000000000040139a in std::less<int>::operator() (this=0x604018,
__x=@0x21001: <error reading variable>, __y=@0x7fffffffddb8: 97)
at /usr/include/c++/4.6/bits/stl_function.h:236
236 { return __x < __y; }
怎么了?