解题思路:
注意事项:
参考代码:#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 人评分
K-进制数 (C++代码)浏览:852 |
C二级辅导-同因查找 (C语言代码)浏览:661 |
最长单词 (C语言代码)浏览:1363 |
printf基础练习2 (C语言代码)浏览:942 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:655 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:504 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:682 |
字符串比较 (C语言代码)浏览:681 |
输出九九乘法表 (C语言代码)浏览:1048 |
整除问题 (C语言代码)浏览:523 |