#include
#include
#include
//#include"eg2_3.h"
#define MAXSIZE 100 //顺序表的最大长度
typedef struct{
char* stuNo;
char* stuName;
char* stuSex;
int mathScore;
int chinScoee;
}DataType; //顺序表中数据元素的类型DataType,这里假设为int
//顺序表的类型
typedef struct{
DataType *data; //一维数组data用于存放表节点
int length; //线性表当前的长度
}SeqList;
//初始化
void InitList(SeqList L)
{
L->data=(DataType)malloc(sizeof(DataType)*MAXSIZE);
L->length=0; //元素的个数为零
}
//求表长
int ListLength(SeqList *L)
{
return L->length;
}
//取值
DataType GetNode(SeqList *L,int i)
{
if(iL->length)
printf("位置错误\n");
return L->data[i];
}
//定位
int LocateNode(SeqList *L,DataType e)
{
int i=1;
while(i<=L->length &&!strcmp( L->data[i].stuNo,e.stuNo))
i++;
if(i>L->length)
return -1;
else
return i;
}
//插入
void InsertList(SeqList *L,DataType e,int i)
{
int j;
if(iL->length+1)
printf("位置错误\n");
if(L->length>=MAXSIZE)
printf("错误,表空间溢出\n");
for(j=L->length;j>=i;j--)
{
L->data[j+1]=L->data[j];
L->data[i]=e;
L->length++;
}
}
void Output(SeqList *L)
{
int i;
for(i=1;i<=L->length;i++)
printf("%s\t%s\t%s\t%5d\t%5d\t\n",L->data[i].stuNo,L->data[i].stuName,L->data[i].stuSex,L->data[i].mathScore,L->data[i].chinScoee);
printf("\n");
}
void main()
{
SeqList La;//定义这种结构的顺序表La
InitList(&La);//初始化这个顺序表
DataType re1,re2,re3; //定义结构类型变量
//对成员进行赋值
re1.stuNo="20121101"; re1.stuName="陈曦";re1.stuSex="男";re1.mathScore=95;re1.chinScoee=92;
re2.stuNo="20121102"; re2.stuName="李晓红";re2.stuSex="女";re2.mathScore=86;re2.chinScoee=98;
re3.stuNo="20121103"; re3.stuName="魏海燕";re3.stuSex="女";re3.mathScore=99;re3.chinScoee=88;
//对表元素进行赋值
InsertList(&La,re1,1);
InsertList(&La,re2,2);
InsertList(&La,re3,3);
Output(&La);//输出这个表
}
求表长和取值函数没有其他函数调用它,他们的 返回值给我谁?