【项目1-顺序表的基本运算】
来源:互联网 发布:旧电脑安装linux 编辑:程序博客网 时间:2024/06/05 16:49
(1)目的是要测试“建立线性表”的算法CreateList,为查看建表的结果,需要实现“输出线性表”的算法DispList。在研习DispList中发现,要输出线性表,还要判断表是否为空,这样,实现判断线性表是否为空的算法ListEmpty成为必要。这样,再加上main函数,这个程序由4个函数构成。main函数用于写测试相关的代码。
主要函数:
运行结果:
程序的结构如下所示:
头文件:
#ifndef FUKA_H_INCLUDED#define FUKA_H_INCLUDED#include"fuka.h"#include <iostream>#define MaxSize 50typedef int ElemType;typedef struct{ ElemType date[MaxSize]; int length;}SqList;void CreateList(SqList *&L,ElemType a[],int n);void DispList(SqList*L);bool ListEmpty(SqList *L);#endif // FUKA_H_INCLUDED
主要函数:
#include <iostream>#include "fuka.h"#include <malloc.h>using namespace std;void CreateList(SqList *&L,ElemType a[],int n){ int i; L=(SqList *)malloc(sizeof(SqList)); for(i=0;i<n;i++) { L->date[i]=a[i]; } L->length=n;}void DispList(SqList *L){ int i; for(i=0;i<L->length;i++) cout<<L->date[i]<<" "; cout<<endl;}bool ListEmpty(SqList *L){ return(L->length==0);}Main 函数:
#include <iostream>#include "fuka.h"using namespace std;int main(){ SqList *l; ElemType a[6]={3,4,6,8,9,5}; CreateList(l,a,6); if(ListEmpty(l)) return 0; else DispList(l); return 0;}
运行结果:
学习心得:
通过自己的编写,加深了对顺序表的印象与理解。
0 0
- 项目1-顺序表的基本运算
- 【项目1-顺序表的基本运算】
- 【顺序表项目1 - 顺序表的基本运算】
- 第三周项目1-顺序表的基本运算
- 第三周项目(1):顺序表的基本运算
- 2015-9-14 项目1- 顺序表的基本运算
- 第三周实践项目1-顺序表的基本运算
- 第3周 项目1-顺序表的基本运算
- 第三周—项目1 顺序表的基本运算
- 第三周 项目1 - 顺序表的基本运算
- 第三周项目1顺序表的基本运算
- 【第3周 项目1 - 顺序表的基本运算】
- 第3周 项目1 - 顺序表的基本运算
- 第三周 项目1-顺序表的基本运算
- 第3周项目1顺序表的基本运算
- 第3周项目1-顺序表的基本运算
- (第三周项目1)顺序表的基本运算
- 第3周 项目1 - 顺序表的基本运算
- copypng emitted errors
- 面向对象——封装
- oracle 函数
- ButterKnife java.lang.ClassCastException: android.view.View cannot be cast to android.app.Activity
- Genymotion模拟器安装Genymotion-ARM-Translation变copy
- 【项目1-顺序表的基本运算】
- 第3周项目4-顺序表应用问题(2)
- DOM三大方法的区别
- Fragment中onOptionsItemSelected方法不起作用的解决方法
- 第3周项目3-求集合并集
- ORACLE 12C新特性——CDB与PDB
- hdu3715 Go Deeper--二分 & 2-sat
- 自定义View签名画板并保存
- Android Studio 错误 com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536