这段C代码神马意思
#include<stdio.h>#include<stdlib.h>
#define ERROR 0
#define OK 1
struct STU
{
char name;
char stuno;
int age;
int score;
}stu;
struct LIST
{
struct STU stu;
int length;
}L;
int printlist(struct LIST L)
{
int i;
printf("name stuno age score\n");
for(i=0;i<L.length;i++)
printf("%s %s\t%d\t%d\n",L.stu.name,L.stu.stuno,L.stu.age,L.stu.score);
printf("\n");
}
int listinsert(struct LIST *L,int i,struct STU e)
{
struct STU *p,*q;
if(i<1||i>L->length+1)
return ERROR;
q=&(L->stu);
for(p=&L->stu;p>=q;--p)
*(p+1)=*p;
*q=e;
++L->length;
return OK;
} /*ListInsert Before i*/
main()
{
struct STU e;
L.length=0;
strcpy(e.name,"zmofun");
strcpy(e.stuno,"100001");
e.age=80;
e.score=1000;
listinsert(&L,1,e);
printlist(L);
printf("List length now is %d.\n\n",L.length);
strcpy(e.name,"bobjin");
strcpy(e.stuno,"100002");
e.age=80;
e.score=1000;
listinsert(&L,1,e);
printlist(L);
printf("List length now is %d.\n\n",L.length);
getch();
}
正在看数据结构,这才第一张就看不懂。。。
顶起来。。看看谁解答
#include<stdio.h>
#include<stdlib.h>
#define ERROR 0
#define OK 1
/*************************************/
/*********定义学生信息的结构******/
/*************************************/
struct STU
{
char name; //姓名
char stuno; //学号
int age; //年龄
int score; //分数
}stu;
/*************************************/
/*******定义顺序存储的线性表******/
/*************************************/
struct LIST
{
struct STU stu; //学生信息
int length; //学生的个数
}L;
/*************************************/
/*********输出所有学生的信息*******/
/*************************************/
int printlist(struct LIST L)
{
int i;
printf("name stuno age score\n");
for(i=0;i<L.length;i++)
printf("%s %s\t%d\t%d\n",L.stu.name,L.stu.stuno,L.stu.age,L.stu.score);
printf("\n");
}
/*********************************************/
/*在线性表第i个位置上插入一个学生信息e*/
/********************************************/
int listinsert(struct LIST *L,int i,struct STU e)
{
struct STU *p,*q; //定义两个指向STU结构的指针变量
if(i<1||i>L->length+1)//非法情况的处理
return ERROR;
q=&(L->stu); //将线性表中第i位置上的地址赋给指针变量q
/*将线性表中第i位置之后的所有学生向后移动一位*/
for(p=&L->stu;p>=q;--p)
*(p+1)=*p;
*q=e;
++L->length;
return OK;
} /*ListInsert Before i*/
main()
{
struct STU e;//定义一个学生信息e
L.length=0; //初始化线性表
/****************/
/*给学生e赋值*/
/***************/
strcpy(e.name,"zmofun");
strcpy(e.stuno,"100001");
e.age=80;
e.score=1000;
listinsert(&L,1,e);//将学生e插入到线性表的第1个位置
printlist(L);//输出线性表中的内容
printf("List length now is %d.\n\n",L.length);//线性表的长度
/****************/
/*给学生e赋值*/
/***************/
strcpy(e.name,"bobjin");
strcpy(e.stuno,"100002");
e.age=80;
e.score=1000;
listinsert(&L,1,e);//将学生e插入到线性表的第1个位置
printlist(L); //输出线性表中的内容
printf("List length now is %d.\n\n",L.length);//线性表的长度
getch();
}
本帖最后由 LNH_Sniper 于 2011-6-20 22:58 编辑
是一个顺序表结构的简单应用,包括了添加、插入、求表长等基本操作 数据结构里面最简单的一种,学C语言的时候最难的一个程序,线性表的操作 鱼C# 发表于 2011-7-17 00:42 static/image/common/back.gif
数据结构里面最简单的一种,学C语言的时候最难的一个程序,线性表的操作
NO!NO!线性表相对于链表来说!那是2个档次的!本人才自学到(栈和队列) 进来看看是什么!!!!!! 数据结构难学吗? 太简单了吧... 路过学习学习 看不见代码啊 我顶!!!!!!! :loveliness::loveliness:虽然我很菜不过还是看懂了,起码英语不难。 路过 赞一个 我也想知道 看了这么长的代码,感觉做程序员太难了 好长啊
页:
[1]