Double Linked list Delete node
Dnode *del (dnode *head, int num)
{
Dnode *p1, *P2;
P1 = head;
while (num! = P1->data && P1->next! = NULL)
{
P1 = p1->next;
}
if (num = = p1->data)
{
if (P1 = = head)
{
Head = head->next;
Head->pre = NULL;
Free (p1);
}
else if (P1->next = = NULL)
{
P1->pre->next = NULL;
Free (p1);
}
Else
{
P1->next->pre = p1->pre;
P1->pre->next = p1->next;
Free (p1);
}
}
Else
printf ("\ n%d could not been found", num);
return (head);
}
Double-linked list insertion node
Dnode * Insert (dnode *head, int num)
{
Dnode *p0, *P1;
P1 = head;
P0 = (Dnode *) malloc (sizeof (Dnode));
P0->data = num;
while (P0->data > P1->data && p1->next! = NULL)
{
P1 = p1->next;
}
if (P0->data <= p1->data)
{
if (head = = p1)
{
P0->next = p1;
P1->pre = P0;
head = P0;
}
Else
{
P1->pre->next = P0;
P0->next = p1;
P0->pre = p1->pre;
P1->pre = P0;
}
}
Else
{
P1->next = P0;
P0->pre = p1;
P0->next = NULL;
}
return head;
}
int main ()
{
Dnode *head, Stud;
int n, del_num, Insert_num;
Head = creat ();
Print (head);
cout << "\ n Int:";
Cin >> Del_num;
Head = Del (head, del_num);
Print (head);
cout << "\nplease input the Insert data:";
Cin >> Insert_num;
Head = insert (head, insert_num);
Print (head);
return 0;
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Double linked list Delete/Insert node