注释一下此程序

来源:百度知道 编辑:UC知道 时间:2024/06/01 07:07:50
#include <iostream>
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int ElemType;
typedef int Status;

#define LIST_INIT_SIZE 100
typedef struct
{
ElemType *elem;
int length;
int listsize;
}SqList;

Status InitList_Sq(SqList &L){
int i;
L.elem = (ElemType * )malloc(LIST_INIT_SIZE*sizeof(ElemType));
if (! L.elem) exit (OVERFLOW);
for(i=1;i<=5;i++)
scanf("%d",&L.elem[i-1]);
L.length = 5;
L.listsize = LIST_INIT_SIZE;
return OK;
}//InitList_Sq
Status PrintList_Sq(SqList L){
int i;
printf("顺序表中的元素为: ");
for (i=1;i<=L.length;i++)
printf("%d ",L.elem[i-1]);
printf("\n")

就怕我注释完了,分你已经给人了。。。

有什么可以个别说,因为没可能每一句都加注释,我觉得貌似有点点难的都注释了.

//这应该是一个线性表的实现吧 ,一看就知道是数据结构的样板题
#include <iostream>
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int ElemType;
typedef int Status;

#define LIST_INIT_SIZE 100

//定义一个结构体数组,储存每一个节点
typedef struct
{
ElemType *elem; //储存空间基址
int length; //长度
int listsize; // 当前分配的储存容量 (以sizeof(ElemType 为单位))
}SqList;

//初始化线性表函数
Status InitList_Sq(SqList &L){
int i;
//构造一个空的线性表 L
L.elem = (ElemType * )malloc(LIST_INIT_SIZE*sizeof(ElemType));
if (! L.elem) exit (OVERFLOW); //储存分配失败
for(i=1;i<=5;i++)
scanf("%d",&L.elem[i-1]);
L.length = 5;
L.listsize = LIST_INIT_SIZE; //初始储存容量
return OK;
}//InitList_Sq

//按顺序打印出每一个节点 函数
Status PrintList_Sq(SqList L){
int i;
printf("顺序表中的元素为: ");
for (i=1;i