我的问题是当我插入数字时它可以工作但是如果我想在中间插入它会被插入但不打印下一个节点我不知道它是删除它们还是无权访问它们。
struct node {
int data ;
struct node *prev;
struct node *next;
};
struct node* head = NULL;
这是有问题的函数插入。
void insert(int key) {
struct node *pred=head, *succ;
struct node *temp2, *temp;
if (head==NULL) {
head = (struct node *) malloc(sizeof(struct node));
head->data = key;
head->prev = NULL;
head->next = NULL;
} else {
temp2 = (struct node*) malloc(sizeof(struct node));
temp2->data = key;
temp = head;
while(temp->next!=NULL && temp->next->data < key) {
pred= temp->next;
temp = temp->next;
}
printf("******pred : %d \n",pred->data);
//printf("******temp-next %d \n",temp->next->data);
if (temp->data < key) {
temp->next = temp->next->next;
temp->next = temp2;
temp2->prev = temp;
temp2->next = pred->next->next;
} else {
//temp2->next= temp;
//temp->prev = NULL;
temp2->next = head;
//head->prev = temp2;
head = temp2;
printf("**** temp : %d",temp->data);
printf("**** temp2 : %d",temp2->data);
printf("here\n");
//temp = temp2 ->prev;
//temp->prev = NULL;
}
}
}