解题思路:
注意事项:
参考代码:#include <stdio.h>
#include <stdlib.h>
typedef int ElemType;
typedef struct LNode{
ElemType data;
struct LNode *next;
}*LinkList,LNode;
void CreatList(LinkList &L,int n){
L=(LinkList)malloc(sizeof(LNode));
LNode *s,*r=L;
int x;
for (int i=0;i<n;i++){
s=(LNode *)malloc(sizeof(LNode));
scanf("%d",&x);
s->data=x;
r->next=s;
r=s;
}
r->next=NULL;
}
void DeleteList(LinkList &L,ElemType x){
LNode *pre=L;
LNode *p=L->next;
LNode *q;
while (p!=NULL){
if (p->data==x){
q=p;
pre->next=p->next;
p=p->next;
free(q);
}else{
pre=p;
p=p->next;
}
}
}
void Print(LinkList L){
LNode *p=L->next;
while (p!=NULL){
printf("%d ",p->data);
p=p->next;
}
}
int main(){
LinkList L;
int n,x;
scanf("%d",&n);
CreatList(L,n);
scanf("%d",&x);
DeleteList(L,x);
Print(L);
return 0;
}
0.0分
2 人评分
简单的a+b (C语言代码)浏览:692 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:592 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:543 |
简单的a+b (C语言代码)浏览:579 |
数字游戏 (C++代码)浏览:1184 |
矩形面积交 (C语言代码)浏览:1312 |
图形输出 (C语言代码)浏览:944 |
找出最长的字符串来 (C语言代码)浏览:1770 |
最好的,浏览:563 |
C语言程序设计教程(第三版)课后习题8.9 (C语言代码)浏览:508 |