/* When the single linked list is understood, the double linked list is much better understood, a single linked list is only one pointer in a struct or class that stores the address of the next node, and the double linked list has two pointers in it, one to store the address of the previous node, and one to store the next node's address. Such a linked list is called a double linked list. */
#include <iostream> using namespace std;
struct Node
{
int A;
Node *prior,*next; Front pointer, back pointer
};
int main ()
{
Node *first,*r,*p;
First=new Node (); Because inserting data into a doubly-linked list uses its previous node, or the latter node, so here R represents the second node of first, and the following
R=new Node ();
first->next=r;
r->prior=null;
for (int i=20;i>=0;i--)///21 p pointers are inserted into the list in the first header node in turn.
{
P=new Node ();
p->a=i;
p->next=first->next; The next pointer to the P stores the address of the next pointer store.
p->prior=first; The previous node of P is first, so the address of prior
first->next->prior=p; The original node now stores the address of P.
first->next=p; The next node in the second is P, and here are the sequence of the four statements that need to be noted.
}
p=first->next;
for (int i=0;i<=20;i+=2)
{
while (P->next!=null)
{
if (p->a==i)
{
p->prior->next=p->next; Here is a node that deletes a value of even, and the rest is an odd node
p->next->prior=p->prior;
cout<<p->a<< "";
Delete p;
Break
}
p=p->next;
}
}
p=first->next;
cout<<endl;
while (P->next!=null)
{
cout<<p->a<< ""; The output is an odd node
p=p->next;
}
}