23.12.25 Day5作业

1.

23.12.25 Day5作业_第1张图片

2.

代码:

doublelist_1 insert_rear(doublelist_1 head,datatype element
 38 {
 39     doublelist_1 s=create_1();
 40     if(s==NULL)
 41         return NULL;
 42     s->data=element;
 43     if(NULL==head)
 44     {
 45         head=s;
 46         return head;
 47     }
 48     doublelist_1 p=head;
 49     while(p->next!=head)
 50     {
 51         p=p->next;
 52     }
 53     s->priv=p;
 54     p->next=s;
 55     s->next=head;
 56     head->priv=s;
 57     return head;
 58 }

运行结果:

23.12.25 Day5作业_第2张图片

23.12.25 Day5作业_第3张图片

3.

代码:

109 doublelist_1 delete_head(doublelist_1 head)
110 {
111 //  head=head->next;
112     if(head==NULL)
113         return NULL;
114     doublelist_1 p=head;
115     if(head->next==head)
116     {
117         free(head);
118         head=NULL;
119         return NULL;
120     }
121     while(p->next!=head)
122     {
123         p=p->next;
124     }   
125     doublelist_1 s=head;
126     head=head->next;
127     head->priv=s;
128     printf("%d",head->data);
129     s->next=head;
130     free(p);
131     p=NULL;
132     return head;
133 }           

4.

代码:

 75 doublelist_1 delete_rear(doublelist_1 head)
 76 {
 77     if(head==NULL)
 78         return NULL;
 79     if(head->next==head)
 80     {
 81         free(head);
 82         head=NULL;
 83     }
 84     doublelist_1 p=head;
 85     while(p->next!=head)
 86     {   
 87         p=p->next;
 88     }
 89     doublelist_1 s=p->priv;
 90     s->priv=p->priv->priv->next;
 91     s->next=head;
 92     head->priv=s;
 93     free(p);
 94     p=NULL;
 95     return head;
 96 }
 97   

运行结果:

23.12.25 Day5作业_第4张图片

23.12.25 Day5作业_第5张图片

你可能感兴趣的:(java,前端,服务器)