<span style="font-size: 14px; font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">*Copyright (c) 2015 烟台大学计算机学院</span>
*All right reserved .*文件名称:test.cpp
*作 者 :刘光辉
*完成日期:2015年9月22日
*
*问题描述:输出线性表
*输出描述:输出线性表。
*程序输出:线性表。
*/
#include <stdio.h> //必要的库文件包括
#include <malloc.h>
#define MaxSize 50 //必要的宏定义
typedef int ElemType;
typedef struct
{
ElemType data[MaxSize];
int length;
}SqList;
void CreateList(SqList *&L,ElemType a[],int n); //用数组创建线性表
void DispList(SqList *L); //输出线性表为DisList(L)
bool ListEmpty(SqList *L); //判定是不是空表ListEmpty(L)
//声明实现算法的自定义函数,以及其他必要的自定义函数
//定义用于驱动测试的main函数
int main()
{
SqList *sq;
ElemType x[6]= {5,8,7,2,4,9};
CreateList(sq, x, 6);
DispList(sq);
return 0;
}
//定义各个自定义函数
void CreateList(SqList *&L,ElemType a[],int n)
{
int i;
L=(SqList *)malloc(sizeof(SqList));
for(i=0;i<n;i++)
L->data[i]=a[i];
L->length=n;
}
void DispList(SqList *L)
{
int i;
if(ListEmpty(L))
return;
for(i=0;i<L->length;i++)
printf("%d ",L->data[i]);
printf("\n");
}
bool ListEmpty(SqList *L)
{
return (L->length==0);
}
运行结果:
知识点总结:
通过编写程序,学会了如何输出线性表,如何定义。
学习心得:
在这次编写过程中,大小写不太注意,记着注意每一个函数的意义。