解题思路:
注意事项:
参考代码:
#include<stdio.h>
#include<stdlib.h>
typedef struct STU {
int num;
struct STU* next;
}list;
list* create(int n);
list* DleteL(list* l1,int m);
void output(list* t);
int main()
{
list* head1;
int n, m;
scanf("%d", &n);
head1 = create(n);
scanf("%d", &m);
head1 = DleteL(head1,m);
output(head1);
return 0;
}
list*create(int n)
{
list* temp, *p1, *p2;
p1 = (list*)malloc(sizeof(list));
p1->next = NULL;
temp = p1;
while(n--){
p2 = (list*)malloc(sizeof(list));
p2->next = NULL;
scanf("%d", &p2->num);
temp->next = p2;
temp = p2;
}
return p1;
}
list* DleteL(list*l1, int m)
{
list* p = l1->next,*pr;
pr = p;
while (p->next!= NULL) {
while (p->next!=NULL&&p->num != m) {
pr = p;
p = p->next;
}
if (p->num == m) {
pr->next = p->next;
free(p);
}
p= pr->next;
}
return l1;
}
void output(list* t)
{
while (t->next!= NULL) {
t = t->next;
printf("%d ", t->num);
}
}
0.0分
2 人评分
点我有惊喜!你懂得!浏览:2028 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:643 |
哥德巴赫曾猜测 (C语言代码)浏览:1148 |
ASCII帮了大忙浏览:797 |
C语言程序设计教程(第三版)课后习题1.6 (C++代码)浏览:909 |
成绩转换 (C语言代码)浏览:1048 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:1001 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:504 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:1110 |
DNA (C语言描述,数据结构)浏览:909 |