//要求做一个放入学生的学号,姓名和成绩的顺表
#include
#include
#define MAXSIZE 100
//定义一个结构体类型放学生的基本信息
typedef struct{
char *name;
char *Nom;
char *secore;
}DataType;
DataType stu[MAXSIZE];//定义一个结构体数组
typedef struct{
DataType *data;//定义了一个数组
int length;
}SeqList;
//初始化这个顺序表
InitList(SeqList *L)
{
L->data=(DataType *)malloc(sizeof(DataType)*MAXSIZE);//申请一个这么大的空间
L->length=0;
}
//插入元素
void InsertList(SeqList *L,int location,DataType e)
{
int i=L->length;
//考虑插入的位置
//考虑插入是否会溢出
if(location<1 || location>L->length+1)
printf("插入位置错误\n");
else if(location>=MAXSIZE)
printf("空间溢出\n");
else
while(i>=location)
L->data[i+1]=L->data[i];
L->data[i]=e;
L->length++;
}
OutList(SeqList *L)
{
int length=1;
printf("2******2\n");
//判断表中是否有值
if(L->length==0)
printf("表中没有值\n");
else
while(length<=L->length)
{
printf("3******3\n");
printf("%s %s %s\n",L->data[length].name,L->data[length].Nom,L->data[length].secore);
length++;
}
}
void main()
{
int length;
int i;
int location;
SeqList L;
InitList(&L);
for(i=1;i<=2;i++)//理论最大一百,用i<=2来进行测试
{
printf("输入位置\n");
scanf("%d",&location);
printf("请依次输入学生姓名 学号 分数中间用空格分隔\n");
scanf("%s %s %s",&stu[i].name,&stu[i].Nom,&stu[i].secore);
InsertList(&L,location,stu[i]);
}
printf("1******1\n");
OutList(&L);
}
从测试结果看是输出函数出问题了,但是就是找不出来,请求帮助,谢谢!