1

我似乎遇到了分段错误,并且似乎错误来自对 tra 的调用,但我无法确切地看到我编写的代码有什么问题。真的没有头绪,有没有想给我提示的?非常感谢。

struct node *tra(struct node * start) {
  struct node * current = start;       
  return current; }

Table ins(Key_Type input, Table table) {
  if ((find(input, table)) == FALSE) {
    struct node *newVal = tra(table -> head, input);
    newVal -> element = input;

我已经定义了一个结构节点,其中包含头、左和右元素。我确定 tra 在为空时返回 current,因为我正在创建一棵一开始为空的树,因此所有节点都将为空。

4

2 回答 2

1

tra看起来很可疑。支票有什么用?如果currentNULL返回它,否则从堆栈中落下并将垃圾返回给调用者。

于 2013-02-16T18:12:17.527 回答
1

那里发生了一些奇怪的事情。

if (current == NULL)
  return current;

为什么return current?电流是null?

struct node *new = tra(table -> head, input);

tra接受一个论点?

I'd recommend you use gdb. Learn to use it now, and it will give you the power to answer this question yourself. It's not difficult.

于 2013-02-16T18:13:40.790 回答