云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 《数据结构实验指导书》

《数据结构实验指导书》

  • 62 次阅读
  • 3 次下载
  • 2025/5/23 4:52:51

第一部分 上机实践

int ListLength_sq(SqList L) //求长度操作函数定义 { //代码略 }

Status GetElem_sq(SqList L, int i, LElemType &e) //取元素操作函数定义 { //代码略 }

Status ListInsert_sq(SqList &L, int i, LElemType e) //插入操作函数定义

{ //代码略 }

Status ListDelete_sq(SqList &L, int i, LElemType &e) //删除操作函数定义 { //代码略 }

int compareTo(LElemType e1,LElemType e2); //元素比较函数声明

int LocateElem_sq(SqList L, LElemType e) //查找操作,返回第一个与e相等的元素的位序 { int i;

for(i=0;i

if(compareTo(L.Elem[i],e)==0) return i+1; return 0; }

void visitListElem(LElemType e); //元素访问函数声明 void ListTraverse_sq(SqList L) //顺序表遍历操作 { int i;

for(i=0;i<=L.Length-1; i++) visitListElem(L.Elem[i]); printf(\}

void InputElem(LElemType &e); //输入元素e的函数声明 void CreatList_sq(SqList &L, int n) //顺序表创建操作 { int i;

LElemType e; InitList_sq(L);;

printf(\ for(i=0; i

ListInsert_sq(L,i+1, e); } }

(2)顺序表应用程序设计

在此以采用顺序表表示集合为例,设计程序实现集合并集、插入元素、删除元素等运算。同学还可自行设计其他顺序表的应用实例。

-3-

第一部分 上机实践

#include #include \ #include \

typedef int LElemType; //定义元素类型为int类型 #include \

int compareTo(LElemType e1,LElemType e2) //元素比较函数定义 { return e1-e2; }

void visitListElem(LElemType e) //元素访问函数定义 { printf(\ \ }

void InputElem(LElemType &e) //输入元素e函数定义 { scanf(\ }

void SetUnion(SqList &La, SqList Lb) //集合并集运算 { //代码略 }

void AddToSet(SqList &L, LElemType e) //将元素e插入集合中 { if(!LocateElem_sq(L,e))

ListInsert_sq(L,ListLength_sq(L)+1,e); }

void DecFromSet(SqList &L, LElemType e) //在集合中删除元素e { int i;

i=LocateElem_sq(L,e);

if(i) ListDelete_sq(L,i,e); }

int main()

{ SqList La,Lb; LElemType e;

printf(\ //创建集合La printf(\ //创建集合Lb printf(\ printf(\ SetUnion(La,Lb);

printf(\ printf(\ scanf(\ AddToSet(La,e);

printf(\

-4-

第一部分 上机实践

printf(\ scanf(\ DecFromSet(Lb,e);

printf(\

if(ListEmpty_sq(Lb)) printf(\ else printf(\ return 0; }

(3)完整代码 -5-

第一部分 上机实践

-6-

搜索更多关于: 《数据结构实验指导书》 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

第一部分 上机实践 int ListLength_sq(SqList L) //求长度操作函数定义 { //代码略 } Status GetElem_sq(SqList L, int i, LElemType &e) //取元素操作函数定义 { //代码略 } Status ListInsert_sq(SqList &L, int i, LElemType e) //插入操作函数定义 { //代码略 } Status ListDelete_sq(SqList &L, int i, LElemType &e) //删除操作函数定义 { //代码略 } int compareTo(LElemType e1,LElemType e2); //元素比较函数声明 int LocateE

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com