太过平凡的小蚂蚁 2015-03-21 06:57 采纳率: 26.9%
浏览 1994

顺序表的 问题 求指教!

#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);//输出这个表

}

求表长和取值函数没有其他函数调用它,他们的 返回值给我谁?

  • 写回答

1条回答 默认 最新

  • threenewbee 2015-03-21 07:19
    关注

    你可以写一个函数,但是不调用它,就当它不存在,这是允许的。

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器