- 3
- 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)
您可能关注的文档
最近下载
- 2025春统编版(2024)道德与法治一年级下册教学计划.docx VIP
- 2025版本成人胃肠功能障碍患者营养治疗指南解读最终版PPT演示课件.pptx VIP
- 最强大脑总题库之一(共800题).pdf VIP
- 病房护理设备器具项目绩效评估报告.docx VIP
- 创建山东省建设工程优质结构杯交流材料.pdf VIP
- 汽车制动系统之卡钳.doc VIP
- 冀少版(2024新版)七年级下册生物期末复习知识点提纲详细版.docx
- 年度供应商审核计划 .xls VIP
- 2026小学语文三年级下册阅读理解必备题型专项练习题库(附答案解析).pdf
- 浙商证券-债市专题报告-风格维度下的可转债多因子体系.pdf
原创力文档

文档评论(0)