C中的链表问题

来源:百度知道 编辑:UC知道 时间:2024/06/13 23:44:06
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#define len sizeof(struct student)
void input();
void output();
struct student
{
int num;
char name[10];
float score;
struct student *next;
};
struct student *head,*p,*q;
main ()
{
int as;
while(1)
{
printf("欢迎你的使用1是输入2是输出3退出");
scanf("%d",&as);
switch(as)
{ case 1:system("cls");input();break;
case 2:system("cls");output();break;
case 3:system("cls");system("exit");exit(0);
}
}
}
void input()
{
int i;
char b;
head=q=(struct student *)malloc(len);
printf("请输入第1个学生的学号:");
scanf("%d",&head->num);
printf("请输入第1个学生的姓名:");
scanf("%s",head->name);
printf("请输入第1个学生的成绩:");
s

你把那个FOR循环换成WHILE循环,在结构体中加入学号这一项,通过WHILE来进行判断,应该可以解决,至于那个链表的排序可以通过冒泡算法来实现.呵呵,代码没空写,你可以到网上去参考个冒泡算法应该没问题吧,呵呵

这样就可以了
#include<stdlib.h>
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#define len sizeof(struct student)
void input();
void output();
struct student
{
int num;
char name[10];
float score;
struct student *next;
};
struct student *head,*p,*q;
main ()
{
int as;
while(1)
{
printf("欢迎你的使用1是输入2是输出3退出");
scanf("%d",&as);
switch(as)
{ case 1:system("cls");input();break;
case 2:system("cls");output();break;
case 3:system("cls");system("exit");exit(0);
}
}
}
void input()
{
int i;
/*char b;*///这个是你没有使用的变量??
head=q=(struct student *)malloc(len);
printf("请输入第1个学生的学号:");