分段故障二叉树遍历

时间:2018-04-10 03:50:38

标签: c file binary-tree singly-linked-list

所以我一直在运行和测试我的代码,一切似乎一直在工作,直到我为我的树的预订和后序遍历添加了2个函数。

分配是为具有随机数字集的输入文件创建链接列表和树。链接列表和树遍历都需要在单独的函数中打印出来,我无法找到出错的地方。

我一直在

分段错误(核心转储)

这是我的代码:



let str = "aaa",
  reg = /aa/g,
  next = reg.exec(str),
  res = [];
while (next) {
  res.push(next[0]);
  reg.lastIndex = next.index + 1;
  next = reg.exec(str);
}
console.log(res);




1 个答案:

答案 0 :(得分:0)

branch *leaf;未初始化。您的代码期望叶指针为NULL。试试branch *leaf = NULL;

此外,看起来freeList两次释放head,这是未定义的行为。

相关问题