[問題] 指標指向NULL
小的程式是要建一顆Tree
但是children數是動態的
於是小的想設計一Linking List叫children
包在叫TreeNode的Object裡面
裡面有TreeNode*和children*
要讀的時候就掃這個List
終止條件為->next=NULL
於是小的都會先把next assign成NULL
當有東西(string)進來時 再new children
我想請問一下
設成NULL再new會不會有問題呢?
因為我在debug發現很莫名的現象
就是在建Tree時 新增下面的leafnode時
莫名其妙Root的data也一起被改掉了= =
可是那時pointer並沒有指向Root= =
而且每次重開程式狀況都不大一樣= =
不知道是不是記憶體上的問題
麻煩各位了
喔對了 我是用Turbo C= =
因為CodeBlock 的debug我一直不太會用(按continue它就說debugger中止
設breakpoint也沒用= =)
Dev-c則說我有segmentation fault
不知道是不是因為這樣呢?
問題有點弱 請多多包涵> <
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.62.74.142
推
08/27 00:50, , 1F
08/27 00:50, 1F
→
08/27 00:52, , 2F
08/27 00:52, 2F
→
08/27 01:07, , 3F
08/27 01:07, 3F
推
08/27 01:45, , 4F
08/27 01:45, 4F
→
08/29 13:48, , 5F
08/29 13:48, 5F
t1.root=new TreeNode;
strcpy(t1.root->data,clause);
q1=&(t1.root->children);
q1=&那行似乎有問題
這樣寫有什麼問題嗎
謝謝各位
struct childchain
{
TreeNode* child;
childchain* next;
};
class TreeNode
{
friend class Tree;
public:
childchain children;
int vocabnum;
char *data;
};
※ 編輯: ok456 來自: 61.62.94.142 (08/29 19:08)
→
08/29 20:36, , 6F
08/29 20:36, 6F
→
08/29 21:17, , 7F
08/29 21:17, 7F
→
08/29 21:41, , 8F
08/29 21:41, 8F
→
08/29 21:41, , 9F
08/29 21:41, 9F
→
08/29 22:03, , 10F
08/29 22:03, 10F
→
08/29 22:03, , 11F
08/29 22:03, 11F
→
08/29 22:06, , 12F
08/29 22:06, 12F
→
08/29 22:08, , 13F
08/29 22:08, 13F
→
08/29 22:08, , 14F
08/29 22:08, 14F
→
08/29 22:13, , 15F
08/29 22:13, 15F