【发布时间】:2021-01-20 09:08:30
【问题描述】:
我正在用 C++ 编写一个拼贴练习程序,但我不知道为什么会看到这个错误
进程以退出代码 139 结束(被信号 11:SIGSEGV 中断)
只是为了测试类,还不完整
如果我删除 add('a'); 程序成功运行但任何函数调用都会导致此错误!
问题是以括号/括号形式读取一棵树并以链表形式制作一棵树
#include<iostream>
using namespace std;
class Tree
{
public:
char data;
Tree *right;
Tree *left;
};
Tree *root;
Tree *temp;
void add(char c)
{
root->data = c;
}
void addR(char c)
{
temp = new Tree;
temp->data = c;
root->right = temp;
}
void addL(char c)
{
temp = new Tree;
temp->data = c;
root->left = temp;
}
int main()
{
cout<<2;
add('a');
return 0;
}
【问题讨论】:
-
root未初始化。 -
谢谢你,它正在工作
标签: c++