- 6
- 0
- 约7.53千字
- 约 8页
- 2021-12-10 发布于福建
- 举报
#includestdio.h
#define null 0
#define len sizeof(struct lnode)
int n;
struct lnode *creatlist();
struct lnode *listinsert();
struct lnode *listdel();
struct lnode{
int a;
struct lnode *next;
};
struct lnode *head;
void main()
{
int n;
do{
printf(===== 链式表练习 =====\n);
printf( 请选择操作: \n);
printf( 1、建立链式表 \n);
printf( 2 、插入新元素 \n);
printf( 3 、删除元素 \n);
printf(====================\n);
scanf(%d,n);
switch(n)
{
case 1:creatlist();break;
case 2:listinsert();break;
case 3:listdel();break;
default:printf( 选择错误,请确认输入! \n);break;
}
}while(1);
}
struct lnode *creatlist()// 建立链表
{
struct lnode *p1,*p2,*p0;
n=0;
head=null;
p1=(struct lnode *)malloc(len);
printf( 请输入初始元素: \n);
scanf(%d,p1-a);
p1-next=null;
while(p1-a!=0)
{
++n;
if(n==1) head=p1;
else p2-next=p1;
p2=p1;
p1=(struct lnode *)malloc(len);
scanf(%d,p1-a);
p1-next=null;
}
free(p1);
printf( 建立链表成功! \n);
printf( 建立的链表为: \n);
p0=head;
do
{
printf(%d ,p0-a);
p0=p0-next;
}while(p0!=null);
printf(\n);
free(p0);
return(head);
}
struct lnode *listinsert()// 插入链表元素
{
int i,j=1;
struct lnode *p,*q,*p0;
p=p0=head;
q=(struct lnode *)malloc(len);
printf( 请选择插入的位置: \n);
scanf(%d,i);
printf( 请输入要插入元素的值: \n);
scanf(%d,q-a);
while(ji-1)
{
p=p-next;
j++;
}
q-next=p-next;
p-next=q;
free(p);
printf( 插入成功! \n)
您可能关注的文档
最近下载
- 烫伤应急处理培训课件.ppt VIP
- 中国生物多样性保护优先区域范围.PDF VIP
- 原发性胆汁性胆管炎诊疗指南(2025年版).pptx VIP
- 汽车车载网络及总线技术 教案全套 1.1 车载网络系统认知 ---6.3 MOST总线系统认知.docx
- 2025年新疆公务员省考《行测》真题(含答案).docx VIP
- 宝洁(SIMPL).pdf
- 2024年新疆公务员省考《行测》真题(含答案).docx VIP
- 2025年济南高考德语真题试卷(含答案解析).docx
- 2025最新初一历史重要历史事件时间轴整理.docx VIP
- 2025年枣庄科技职业学院单招职业技能考试题库完整版.docx VIP
原创力文档

文档评论(0)