BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #75487同步于 2013/12/3
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

[问题]二叉树建立与遍历的问题

century
2013/12/3镜像同步1 回复
#include "iostream" using namespace std; struct node{ char data; node *left; node *right; }; node *createBT(){ node *root; char ch; cin>>ch; if(ch == '#'){ root == NULL; }else{ root = new node; root->data = ch; root->left = NULL; root->right = NULL; cout<<"请输入"<<ch<<"的左子结点"<<endl; root->left = createBT(); cout<<"请输入"<<ch<<"的右子结点"<<endl; root->right = createBT(); } return root; } void pre(node *root){ if(root == NULL) return ; cout<<root->data; pre(root->left); pre(root->right); } int main(int argc, char const *argv[]) { node *root ; root = createBT(); pre(root); return 0; } 为什么我这段代码是segment fault呢
订阅后,新回复会通过你的通知中心匿名送达。
1 条回复
b295181573机器人#1 · 2013/12/3
root == NULL; 看了一遍代码尽然没发现,编译之后才知道。编译器是程序员的好朋友!