第三周项目 1 顺序表的基本运算
2017-09-20 19:50
176 查看
/*烟台大学计算机学院 文件名称:项目三.cpp 作者:董玉祥 完成日期: 2017 9 20 问题描述:目的是要测试“建立线性表”的算法CreateList,为查看建表的结果,需要实现“输出线性表”的算法DispList。在研习DispList中发现,要输出线性表,还要判断表是否为空,这样,实现判断线性表是否为空的算法ListEmpty成为必要。这样,再加上main函数,这个程序由4个函数构成 */
问题及代码:
#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) { L=(SqList *)malloc(sizeof(SqList));//分配存放线性表的空间 for(int i=0;i<n;i++) L->data[i]=a[i]; L->length=n; } //判断线性表是否为空 bool EmptyList(SqList *L) { if(L->length==0) return true; else return false; } //输出线性表 void DispList(SqList *L) { int i=0; for(i=0;i<L->length;i++) printf("%d ",L->data[i]); printf("\n"); } int main() { SqList *sq; ElemType a[6]={1,2,3,4,5,6}; ElemType x; CreateList(sq,a,6); DispList(sq); return 0; }
运行结果及截图:
相关文章推荐
- 第三周实践项目1-顺序表的基本运算
- 第三周项目1——顺序表的基本运算
- 第三周—项目1-顺序表的基本运算
- 第三周项目1 顺序表的基本运算(2)
- 第三周项目1 顺序表的基本运算
- 第三周 项目1-顺序表的基本运算
- (第三周项目1)顺序表的基本运算
- 第三周 项目1—顺序表的基本运算(1)
- 第三周 【项目1 - 顺序表的基本运算】
- 第三周项目1-顺序表的基本运算
- 第三周 【项目1 - 顺序表的基本运算】
- 第三周 项目一:顺序表的基本运算
- 第三周项目1顺序表的基本运算
- 第三周-项目1-顺序表的基本运算
- 第三周项目一(3)—顺序表的基本运算
- 第三周——项目1 顺序表的基本运算
- 第三周项目1-顺序表的基本运算
- 第三周——项目一—顺序表的基本运算(1)
- 第三周 【项目1 - 顺序表的基本运算】
- 第三周项目1-顺序表的基本运算