前言:設計一支程式具備以下功能
1. 在雙向鏈結串列中加入節點
2. 在雙向鏈結串列中刪除節點
struct node *pre;
int data;
struct node *next;
};
struct node *head=NULL;
struct node A={NULL,1,NULL};
struct node B={NULL,2,NULL};
struct node C={NULL,3,NULL};
struct node Q={NULL,17,NULL};
head=&A;
A.pre=NULL;
A.next=&B;
B.pre=&A;
B.next=&C;
C.pre=&B;
C.next=&D;
D.pre=&C;
D.next=&E;
E.pre=&D;
E.next=NULL;
printList(head);
insertDoubleList(&head,&B,&Q);
printList(head);
deleteDoubleList(&head,&B);
printList(head);
if(*head==NULL)
*head=q;
else if(p->next==NULL){
q->pre=p;
p->next=q;
}else{
q->pre=p;
q->next=p->next;
p->next=q;
p->next->pre=q;
}
if(*head==NULL)
printf("Linked List is empty.\n");
else if(p->next==NULL)
p->pre->next=p->next;
else{
p->pre->next=p->next;
p->next->pre=p->pre;
}
struct node *P=head;
if(P==NULL){
printf("stack is empty.\n");
return;
}
printf("Linked List data:");
while(1)
{
printf("%d",P->data);
if(P->next==NULL)
{
printf("\n");
break;
}
else
{
P=P->next;
printf("->");
}
}
留言列表