# 简单链表

#include<stdio.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{
long num;
float score;
struct student*next;
};
int n;

struct student*creat(void)
{
struct student*p1,*p2;
n=0;
p1=p2=(struct student* )malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
while(p1->num!=0)
{n=n+1;
if(n==1)
else
p2->next=p1;
p2=p1;
p1=(struct student* )malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
}
p2->next=NULL;
}
{
struct student *p;
printf("这%d个记录分别是:/n",n);
do
{
printf("%d,%5.1f/n",p->num,p->score);
p=p->next;
}while(p!=NULL);
}

{
struct student *p1,*p2;

while(num!=p1->num&&p1->num!=NULL)
{p2=p1;p1=p1->next;}

if(num==p1->num)
printf("查找元素为%d,它的值为%f",p1->num,p1->score);
else
printf("没找到");
end:
}

struct student *del(struct student * head,long num)
{
struct student *p1,*p2;

while(num!=p1->num&&p1->num!=NULL)
{p2=p1;p1=p1->next;}

if(num==p1->num)
{
else
p2->next=p1->next;
printf("delete:%d/n",num);
n=n-1;
}
else
printf("没找到");
end:
}

struct student * paixu(struct student *head)
{
struct student*p1,*p2;
int i,j;
float temp;int m;
for(i=0;i<n;i++)
p1=p1->next;
for(j=0;j<=n-i;j++)
{if(p1->score>p2->score)
{
temp=p1->score;m=p1->num;
p1->score=p2->score;p1->num=p2->num;
p2->score=temp;p2->num=m;
if(p1->next!=NULL)
{p1=p1->next;p2=p2->next;}
}
}
}
end:
}

struct student * insert(struct student *head,struct student*stud)
{
struct student *p1,*p2,*p3;
p2=stud;
else
while((p2->num>p1->num)&&(p1->next!=NULL))
{p3=p1;
p1=p1->next;
}
if(p2->num<=p1->num)
else
p3->next=p2;
p2->next=p1;
}
else
{p1->next=p2;
p2->next=NULL;
}
n=n+1;
}

main()
{
long del_num;
long find_num;
int a=0;
l:printf("/n请输入要执行的操作序号：/n");
printf("0 退出/n1 创建/n2 删除/n3 插入/n4 查找/n5 排序/n");
scanf("%d",&a);
if(a==0)goto l0;
else if(a==1)goto l1;
else if(a==2)goto l2;
else if(a==3)goto l3;
else if(a==4)goto l4;
else if(a==5)goto l5;
else {printf("输入错误，请重新输入");goto l;}

l1:printf("input records:/n");
goto l;
l2:printf("/n输入要删除的序号:/n");
scanf("%ld",&del_num);
while(del_num!=0)
{
printf("输入要删除的序号：");
scanf("%d",&del_num);
}
goto l;
l3:printf("/n输入要插入的序号：");
stu=(struct student *)malloc(LEN);
scanf("%ld,%f",&stu->num,&stu->score);
while(stu->num!=0)
{
printf("输入要插入的序号：");
stu=(struct student *)malloc(LEN);
scanf("%ld,%f",&stu->num,&stu->score);
}
goto l;
l4:printf("/n输入要查找的序号：");
scanf("%ld",&find_num);
while(find_num!=0)
{
printf("输入要查找的序号：");
scanf("%d",&find_num);
}
goto l;

goto l;

l0: printf("%d",n);
}

• 0
点赞
• 0
评论
• 0
收藏
• 一键三连
• 扫一扫，分享海报

08-11 656

11-13 7347
05-20
09-30
07-15
06-30
04-29
08-29 5907
03-21 1万+
06-01
08-19
02-21
10-25 3484
10-31