我正在编写一个数据结构,其中包含一组两个链接列表,堆叠在一起。当试图在我的测试工具中初始化集合时,出现分段错误。我已经评论过所有的价值评估者来测试我是否可以自己弄清楚这个错误,但我不能。问题初始化C中的双重堆栈链接列表
原型的init方法:
测试工具:
int
main()
{
list the_list;
int used = 0;
int values[MAX_VALUES];
char input[LINE_LEN];
char command;
int argument;
int num_found;
bool result;
set_t lower;
set_t upper;
the_list->lower = lower;
the_list->upper = upper;
input[0] = '\0';
input[LINE_LEN-1] = '\0';
fgets(input, LINE_LEN, stdin);
while (*input != 'q') {
num_found = sscanf(input, "%c %d", &command, &argument);
if (num_found > 0) {
switch (command) {
case 'i':
printf ("Request to initialize the set\n");
if (num_found == 1) {
result = set_init(&the_list);
} else {
result = set_init(NULL);
}
printf ("Returned as %d\n", result);
break;
34,0-1 8%
Init方法:
bool
set_init(list *the_list)
{
bool initialized = false;
if (the_list !=NULL) {
/* We have space to initialize. */
the_list->lower->set_size = 0;
/* the_list->lower->head = NULL;
the_list->lower->tail = NULL;
the_list->lower->set_level = 1;
the_list->lower->ready = true;
the_list->upper->set_size = 0;
the_list->upper->head = NULL;
the_list->upper->tail = NULL;
the_list->upper->set_level = 2;
the_list->upper->ready = true;*/
initialized = true;
}
return initialized;
}
而且我对我的设置结构的定义,链表和节点结构:
typedef struct _set_node_t {
test_type_t *data;
struct _set_node_t *next;
struct _set_node_t *below;
} set_node_t;
/* the set itself keeps track of the head and the tail of the linked list */
typedef struct {
int set_size;
bool ready;
set_node_t *head;
set_node_t *tail;
int set_level;
} set_t;
typedef struct {
set_t *lower;
set_t *upper;
}list;
你的意思'如果(i == 1)'? – mihai