我正在編寫一個數據結構,其中包含一組兩個鏈接列表,堆疊在一起。當試圖在我的測試工具中初始化集合時,出現分段錯誤。我已經評論過所有的價值評估者來測試我是否可以自己弄清楚這個錯誤,但我不能。問題初始化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