std :: list(双重链接列表)未知运行时错误
std:: list (doubly linked list) unknown runtime error
我在链接列表上操作困难。我过去已经能够做到这一点,但无法弄清楚为什么我会遇到运行时错误,只是说"该程序已经停止工作,没有解释。我是使用push_back,插入还是任何操作,还是任何操作,到达那条代码,我不知道为什么。这是仅显示用于此特定部分的代码。
#include <iostream>
#include <string>
#include <list>
int main() {
ttree* tree;
tree = new ttree(); //ttree object
tree->insert("a string");//insert a string that has been read in
// passes to ttree insert method
}
class ttree
{
private:
tnode* _tnodes; // pointer to _tnodes
int _maxDepth; // max depth allowance
int _currentDepth; // the depth of current node ( root is depth 1)
}
ttree::ttree() //default ttree constructor
{
_maxDepth = 5;
_currentDepth = 1;
_tnodes = new tnode[26];//create Array of 26 tnodes (A-Z)
//calls tnode constructor
}
void ttree::insert(string key) {
int index = key[_currentDepth - 1] - 'A';
(_tnodes)[index].insert(key, _currentDepth);// passes to tnode insert method
}
class tnode
{
private:
ttree* _nextLevel; // pointer to the ttree at the next level
list<string>* _words; // store keywords
}
tnode::tnode()
{
_nextLevel = NULL;
_words = NULL;
}
bool tnode::insert(string key, int level)
{
cout << key;
_words->push_back(key);// no matter what I do with the linked list here
//it errors out right here
return true;
}
_words
是std::list
的指针。您将其设置为构造函数中的NULL
,而永远不要将其设置为其他任何内容。看起来它不需要是指指针,只需将其直接作为tnode
的成员即可。
相关文章:
- 删除指向指针的指针是运行时错误吗
- c++中的指针和运行时错误
- 无法理解此 return 语句的功能,没有它就会发生运行时错误
- 在同一模拟中使用静脉和静脉_ inet内容时出现运行时错误
- 对单向链表进行排序时出现运行时错误
- 为什么此代码存在运行时错误?
- 你能解释一下什么运行时错误是如何解决它的吗?
- 为什么会出现 gettnig 运行时错误:加载类型为"_Bit_type"(stl_bvector.h) 的空指针?
- 为什么程序在 c++ 中迭代 emtpy 向量时会抛出运行时错误
- 运行时错误:引用绑定到类型为"int"的空指针
- 为什么当 vector 为空时会显示运行时错误?
- C++运行时错误与快速排序算法抛出堆栈转储错误
- 运行时错误:矢量下标超出范围:正在检查空集
- std :: list(双重链接列表)未知运行时错误
- 列表迭代器不可递增?- 运行时错误
- 类链接列表模板运行时错误
- 从整数列表中交叉检查整数运行时错误
- 列表迭代器不可递增 - 运行时错误
- 合并两个排序列表出现运行时错误
- 如果使用 malloc 存储 STL 列表的分配内存,则运行时错误即将到来