




已阅读5页,还剩11页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验一实验一 线性表的应用 include int n j k 声明结构体类型 并确定其成员变量 typedef struct student char name 20 char sex 5 int age long long tel long qq char email 50 person person a 100 输入链表的个人信息 void creat int n if n 100 printf 超出划定内存 判断所存个人信息是否超出内存 else int i 0 for int i 0 i n i printf 依次输入 姓名 性别 年龄 电话号码 QQ 号 Email 地址 回车键隔开 inputname 输入姓名 inputtel 输入电话 scanf d a i age scanf d a i tel scanf d a i qq inputemail 输入 email 地址 输入第 i 个成员数据 void shuru int i printf 依次输入 姓名 性别 年龄 电话号码 QQ 号 Email 地址 回车键隔开 inputname 输入姓名 inputtel 输入电话 scanf d a i age scanf d a i tel scanf d a i qq inputemail 输入 email 地址 创建一个姓名输入方法 void inputname char name 20 for int i 0 i 20 i scanf c 创建电话输入方法 void inputtel char tel 15 for int i 0 i 15 i scanf c 创建 email 输入方法 void inputemail char email 50 for int i 0 i 50 i scanf c 插入方法 插入第 i 个成员 void insert int k if k100 printf 插入位置错 else int i for i n i k i a i 1 a i shuru k 删除第 k 个元素 void dele int k if kn printf 删除位置不存在 else for int k k n k a k a k 1 void main printf 输入您将输入的通讯录人数 scanf d creat n printf 输入插入的位置 scanf d insert k printf 输入删除的位置 scanf d creat j 实验二实验二 求哈夫曼编码 include include include using namespace std define n 5 define m 2 n 1 define infinity 32727 struct HTNode unsigned int weight unsigned int plink rlink llink HuffmanTree struct codetype int start char bits n 1 struct element char symbol codetype code struct element table n 1 inline void select struct HTNode ht 2 n int s int float v1 v2 v1 v2 infinity x1 x2 0 for i 1 i s i if ht i plink 0 if ht i weight v1 v2 v1 x2 x1 v1 ht i weight x1 i else if ht i weight v2 v2 ht i weight x2 i void set huffmantree struct HTNode ht 2 n inline void select struct HTNode ht 2 n int s int int i int s1 s2 for i 1 i m i ht i plink ht i llink ht i rlink 0 for i n 1 i m i 建哈夫曼树 select ht i 1 s1 s2 在 ht k 1 k i 1 中选择两个双亲域为零的最小的 结点 s1 和 s2 s1 和 s2 为最小值所在的下标 ht s1 plink ht s2 plink i ht i llink s1 ht i rlink s2 ht i weight ht s1 weight ht s2 weight void sethufcode struct HTNode ht 2 n struct HTNode p ht void set huffmantree struct HTNode ht 2 n int i s f codetype c for i 1 i n i printf 请输入字符 scanf s printf 请输入相应的权值 scanf d set huffmantree p for i 1 i n i c start n 1 s i f ht s plink do c start if s ht f llink c bits c start 0 else c bits c start 1 s f f ht s plink while f table i code c void OutHuffmanTree struct HTNode ht 2 n int i j codetype c for i 1 i n i printf n c table i symbol c table i code for j c start jnumEdges 8 G numVertexes 5 for i 0 i numVertexes i 初始化图 G vexs i i for i 0 i numVertexes i 初始化图 for j 0 j numVertexes j if i j G arc i j 0 else G arc i j G arc j i INFINITY G arc 0 1 3 G arc 0 4 30 G arc 1 2 25 G arc 1 3 8 G arc 2 4 10 G arc 3 4 12 G arc 3 0 20 G arc 3 2 4 G arc 4 0 15 for i 0 i numVertexes i for j i j numVertexes j G arc j i G arc i j Floyd 算法 求网图 G 中各顶点 v 到其余顶点 w 的最短路径 P v w 及带权长度 D v w void ShortestPath Floyd MGraph G Patharc P ShortPathTable D int v w k for v 0 v G numVertexes v 初始化 D 与 P for w 0 w G numVertexes w D v w G arc v w D v w 值即为对应点间的权值 P v w w 初始化 P for k 0 k G numVertexes k for v 0 v G numVertexes v for w 0 w D v k D k w 如果经过下标为 k 顶点路径比原两点间路径更短 D v w D v k D k w 将当前两点间权值设为更小的一 个 P v w P v k 路径设置为经过下标为 k 的顶点 int main void int v w k MGraph G Patharc P ShortPathTable D 求某点到其余各点的最短路径 CreateMGraph ShortestPath Floyd G printf 各顶点间最短路径如下 n for v 0 v G numVertexes v for w v 1 w d k 打印路径顶点 k P k w 获得下一个路径顶点下标 printf d n w 打印终点 printf n printf 最短路径 D n for v 0 v G numVertexes v for w 0 w G numVertexes w printf d t D v w printf n printf 最短路径 P n for v 0 v G numVertexes v for w 0 wnumEdges 11 G numVertexes 8 for i 0 i numVertexes i 初始化图 G vexs i i for i 0 i numVertexes i 初始化图 for j 0 j numVertexes j if i j G arc i j 0 else G arc i j INFINITY G arc 0 1 6 G arc 0 2 4 G arc 0 3 5 G arc 1 4 1 G arc 2 4 1 G arc 3 5 2 G arc 4 6 9 G arc 4 7 7 G arc 5 7 4 G arc 6 8 2 G arc 7 8 4 利用邻接矩阵构建邻接表 void CreateALGraph MGraph G GraphAdjList GL int i j EdgeNode e GL GraphAdjList malloc sizeof graphAdjList GL numVertexes G numVertexes GL numEdges G numEdges for i 0 i adjList i in 0 GL adjList i data G vexs i GL adjList i firstedge NULL 将边表置为空表 for i 0 i G numVertexes i 建立边表 for j 0 j G numVertexes j if G arc i j 0 邻接序号为 j e weight G arc i j e next GL adjList i firstedge 将当前顶点上的指向的结点指针 赋值给 e GL adjList i firstedge e 将当前顶点的指针指向 e GL adjList j in 拓扑排序 Status TopologicalSort GraphAdjList GL 若 GL 无回路 则输出拓扑排序序列并返回 1 若有回路返回 0 EdgeNode e int i k gettop int top 0 用于栈指针下标 int count 0 用于统计输出顶点的个数 int stack 建栈将入度为 0 的顶点入栈 stack int malloc GL numVertexes sizeof int for i 0 inumVertexes i if 0 GL adjList i in 将入度为 0 的顶点入栈 stack top i top2 0 etv int malloc GL numVertexes sizeof int 事件最早发生时间数组 for i 0 inumVertexes i etv i 0 初始化 stack2 int malloc GL numVertexes sizeof int 初始化拓扑序列栈 printf TopologicalSort t while top 0 gettop stack top printf d GL adjList gettop data count 输出 i 号顶点 并计数 stack2 top2 gettop 将弹出的顶点序号压入拓扑序列的栈 for e GL adjList gettop firstedge e e e next k e adjvex if GL adjList k in 将 i 号顶点的邻接点的入度减 1 如果减 1 后为 0 则入栈 stack top k if etv gettop e weight etv k 求各顶点事件的最早发生时间 etv 值 etv k etv gettop e weight printf n if count numVertexes return ERROR else return OK 求关键路径 GL 为有向网 输出 G 的各项关键活动 void CriticalPath GraphAdjList GL EdgeNode e int i gettop k j int ete lte 声明活动最早发生时间和最迟发生时间变量 TopologicalSort GL 求拓扑序列 计算数组 etv 和 stack2 的值 ltv int malloc GL numVertexes sizeof int 事件最早发生时间数组 for i 0 inumVertexes i ltv i etv GL numVertexes 1 初始化 printf etv t for i 0 inumVertexes i printf d etv i printf n while top2 0 出栈是求 ltv gettop stack2 top2 for e GL adjList gettop firstedge e e e next 求各顶点事件的最迟发生时间 ltv 值 k e adjvex if ltv k e weight weight printf ltv t for i 0 inumVertexes i printf d ltv i printf n for j 0 jnumVertexes j 求 ete lte 和关键活动 for e GL adjList j firstedge e e e next k e adjvex ete etv j 活动最早发生时间 lte ltv k e weight 活动最迟发生时间 if ete lte 两者相等即在关键路径上 printf length d n GL adjList j data GL adjList k data e weight int main void MGraph G GraphAdjList GL CreateMGraph CreateALGraph G CriticalPath GL system pause return 0 实验四实验四 Hash 存储 include include define MAX 30 typedef struct node int key int flag int l node next Hashtable MAX Hashtable table void Init table Hashtablei MAX i list i flag 0 list i l 0 list i next NULL void creat table Hashtable int mod 13 int account 12 int date for int i 0 i a
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 项目部归档管理办法
- 长沙指标生管理办法
- 工业园污水回用系统建设方案
- 源网荷储一体化项目用电负荷特性分析及优化方案
- 智慧水务系统防内涝应用方案
- 湖水生态修复效果评估方案
- 安全培训简答题课件
- 源网荷储一体化项目增量配电网建设运营方案
- 城市广场植物资源配置与景观应用研究
- 多学科交叉融合的人才培养策略
- 2025数学步步高大一轮复习讲义人教A版复习讲义含答案
- 《立在地球边上放号》《峨日朵雪峰》联读课件32张高中语文必修上册
- 家具厂封边技能培训
- 重点群体人员本年度实际工作时间表
- DBJ50-T-386-2021 建筑施工现场扬尘控制标准
- 数据科学与大数据技术导论-第1章-数据科学概述
- 健康指南妊娠糖尿病孕期饮食控制的重要性
- 《美丽中国是我家》-教学设计
- 军工行业保密知识传授培训
- 实验动物微生物学和寄生虫学质量控制课件
- 殡葬经济现代墓地投资项目分析报告
评论
0/150
提交评论