第三周项目1(1)

来源:互联网 发布:淘宝上买东西靠谱吗 编辑:程序博客网 时间:2024/06/11 12:12
/*烟台大学计算机学院文件名称:xiangmu.cpp作者:于琛完成日期:2017年9月17日问题描述:顺序表建立输入描述:无输出描述:顺序表的值*/#include <stdio.h>#include <malloc.h>#define MaxSize 50//存储空间大小宏定义typedef int ElemType;  //定义ElemType为inttypedef struct{    ElemType data[MaxSize];  //利用了前面MaxSize和ElemType的定义    int length;} SqList;void CreateList(SqList *&L, ElemType a[], int n);//用数组创建线性表void DispList(SqList *L);//输出线性表DispList(L)bool ListEmpty(SqList *L);//判定是否为空表ListEmpty(L)int main()//主函数{    SqList *p;    ElemType x[6]={1,2,3,4,5,6};    CreateList(p,x,6);    DispList(p);    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);}//空表判断

运行结果:

学习心得:学习到了用顺序表的基本算法实现程序

感受:体会到了学习顺序表的乐趣

原创粉丝点击