yuyuhongss 发表于 2011-6-15 14:21:25

这段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();
}

正在看数据结构,这才第一张就看不懂。。。

wokk 发表于 2011-6-15 19:55:18

顶起来。。看看谁解答

forstd 发表于 2011-6-18 10:52:31


#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:57:43

本帖最后由 LNH_Sniper 于 2011-6-20 22:58 编辑

是一个顺序表结构的简单应用,包括了添加、插入、求表长等基本操作

鱼C# 发表于 2011-7-17 00:42:41

数据结构里面最简单的一种,学C语言的时候最难的一个程序,线性表的操作

棺材 发表于 2011-7-30 20:17:21

鱼C# 发表于 2011-7-17 00:42 static/image/common/back.gif
数据结构里面最简单的一种,学C语言的时候最难的一个程序,线性表的操作

NO!NO!线性表相对于链表来说!那是2个档次的!本人才自学到(栈和队列)

tantrong 发表于 2011-9-10 15:20:07

进来看看是什么!!!!!!

gongheng 发表于 2011-10-28 12:35:39

数据结构难学吗?

闫熙|Yan_Xi 发表于 2011-11-27 16:28:04

太简单了吧...

2004111 发表于 2014-2-3 03:06:13

路过学习学习

183560656 发表于 2014-2-8 03:07:11

看不见代码啊

驻留的习惯 发表于 2014-3-15 19:54:17

我顶!!!!!!!

零少 发表于 2014-7-7 00:08:59

:loveliness::loveliness:虽然我很菜不过还是看懂了,起码英语不难。

网络学习 发表于 2014-7-8 00:30:56

路过 赞一个

繁空.星雨 发表于 2014-7-23 12:20:24

我也想知道

wangerwanger 发表于 2014-7-25 17:59:08

看了这么长的代码,感觉做程序员太难了

zjc7836 发表于 2015-1-21 21:27:39

好长啊
页: [1]
查看完整版本: 这段C代码神马意思