谁能帮助这个分割错误我不断收到。 这段代码很简单,但错误是如此很难搞清楚。
struct Link {
int key;
unsigned data: 2;
struct Link *next;
struct Link *previous;
};
struct Link* addInOrder(struct Link *, struct Link);
int main() {
struct Link *head;
struct Link data1;
struct Link data2;
struct Link data3;
data1.key = 25;
data1.data = 1;
data1.next = NULL;
data2.key = 50;
data2.data = 0;
data2.next = NULL;
data3.key = 100;
data3.data = 2;
data3.next = NULL;
head = NULL;
head = addInOrder(head, data2);
}
struct Link* addInOrder(struct Link *srt, struct Link l) {
if(!srt) {
return &l;
}
struct Link *temp = srt;
while(temp->next && l.key > temp->key)
temp = temp->next;
printf("here\n");
if(l.key > temp->key) {
printf(" 1\n");
temp->next = &l;
l.previous = temp;
}
else {
printf(" 2\n");
l.previous = temp->previous;
l.next = temp;
printf( "2.2\n");
if(temp->previous) {
//printf("%i\n",temp->previous->key);
temp->previous->next = &l;
}
printf(" 2.3\n");
temp->previous = &l;
}
return srt;
}
我一直在addInOrder收到错误在第一行()。 所有的编译器说的是分割错误。
编辑:另外,如果我加上的printf( “...”); if语句,并运行它的权利......不打印