我在学校尝试编写一个简单的家庭作业,并得到错误Segmentation fault (core dumped),以这种方式在 C++ 中实现链表:
struct Word{
string word;
string meaning;
Word * next;
};
struct dictionary{
Word *head = NULL;
int count;
}dict;
string addWord(string word, string meaning){
Word *newWord = new Word;
newWord -> word = word;
newWord -> meaning = meaning;
newWord -> next = dict.head;
dict.head = newWord;
dict.count++;
}
我正在尝试在遇到错误时添加一个单词(节点),我不能使用c ++类,因为是老师的要求,衷心感谢您的帮助!