私の問題は、数字を挿入すると機能することですが、途中で挿入したい場合は挿入されますが、次のノードを出力しません。それらを削除するか、アクセスできないかはわかりません。
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;
}
}
}