#include "stdio.h"
#include "stdlib.h"
typedef struct LNode{
int m;
struct LNode *next;
}LNode, *List;
int main(void){
void add(List L);
void showL(List L);
void dele(List L);
List L=(LNode *)malloc(sizeof(LNode));
L->next=NULL;
add(L);
showL(L);
dele(L);
showL(L);
return 0;
}
void add(List L){
int s;
List q=L;
printf("输入链表长度\n");
scanf("%d",&s);
printf("输入次数还有%d\n",s);
for(;s>0;s--){
List p=(List)malloc(sizeof(LNode));
p->next=NULL;
scanf("%d",&p->m);
q->next=p;
q=q->next;
printf("输入次数还有%d\n",s-1);
}
printf("输入结束\n");
}
void showL(List L){
List p;
p=L->next;
while(p!=NULL){
printf("%d ",p->m);
p=p->next;
}
}
void dele(List L){
printf("请输入想删除的数据");
List p=L->next;
List q=L;
int mm;
scanf("%d",&mm);
while(p->m!=mm)
p=p->next;
while(q->next!=p)
q=q->next;
q->next=p->next;
free(p);
}
12-02
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交