#include"stdio.h"
#include"stdlib.h"
typedef int ElemType;
typedef struct node
{
ElemType data;
struct node *next;
}Lnode;
void outlin(Lnode *h);
void creat();
void insert(Lnode *h, ElemType x, ElemType y);
void Delete(Lnode *h,ElemType x);
Lnode *p,*q,*s,*head;
void main()
{
int x,y,cord;
do{
printf("\n 主菜单 \n");
printf("\n 1 建立线性表 \n");
printf("\n 2 插入一个元素 \n");
printf("\n 3 删除一个元素 \n");
printf("\n 4 结束程序运行 \n");
printf("-----------------------\n");
printf(" 请输入你的选择(1, 2, 3, 4)");
scanf("%d",&cord);
switch(cord)
{
case 1:{ creat(); outlin(head);
}break;
case 2:{ printf("\n x,y=? 注意用逗号分隔");
scanf("%d%d",&x,&y);
insert(head,x,y); outlin(head);
}break;
case 3:{ printf("\n x=?");
scanf("%d",&x);
Delete(head,x); outlin(head);
}break;
case 4:exit(0);
} /*switch */
} while(cord<=4);
} /*main end*/
void creat()
{
ElemType x;
Lnode *ptr;
head=(Lnode*)malloc(sizeof(Lnode));
head->next=NULL;
p=head;
printf("\n x=?");
scanf("%d",&x);
while(x!=-999)
{
ptr=(Lnode*)malloc(sizeof(Lnode));
ptr->data=x;
ptr->next=NULL;
p->next=ptr;
p=ptr;
printf("\n x=?");
scanf("%d",&x);
}/*creat end*/
}
void outlin(Lnode *h)
{
p=h->next;
printf("\n ");
while(p!=NULL)
{
printf(" data=%4d",p->data);
p=p->next;
}
printf("\n 输入结束 \n\n");
} /*outlin end*/
void insert(Lnode *h, ElemType x, ElemType y)
{
s=(struct node*)malloc(sizeof(struct node));
s->data=y;
q=h;
p=h->next;
while(p!=NULL&&p->data!=x)
{
q=p; p=p->next;
}
q->next=s;
s->next=p;
} /*insert end*/
void Delete(Lnode *h,ElemType x)
{
p=h;
while(p->next!=NULL&&p->next->data!=x) p=p->next;
if(p->next==NULL) printf("\n x 不存在 !");
else {
q=p->next;
p->next=q->next;
free(q);
}
} /*delete end*/
lhq.rar_visual c
版权申诉
180 浏览量
2022-09-24
02:23:37
上传
评论
收藏 926B RAR 举报
![avatar](https://profile-avatar.csdnimg.cn/c7605ebd585249f1b630f560f4d9ba6f_weixin_42650811.jpg!1)
我虽横行却不霸道
- 粉丝: 77
- 资源: 1万+
最新资源
- 基于jsp+servlet+mysql蛋糕甜品店购物网站源码+数据库(期末大作业).zip
- Java项目:在线蛋糕商城系统(java+jsp+mysql)源码+数据库+期末大作业.zip
- ZapyaClient10_7-1.apk
- 织梦cms站长导航网站源码.zip
- 基于SSM+MySQL的网络投票调查问卷系统源码+数据库(java期末大作业).zip
- 基于jsp+servlet的宠物商城网站系统源码+数据库(java期末大作业).zip
- 基于Python+Tensorflow实现声纹识别+源代码+文档说明.zip
- java-leetcode题解之第112题路径总和.zip
- java-leetcode题解之第111题二叉树的最小深度.zip
- java-leetcode题解之第110题平衡二叉树.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)