当前位置: 首页 > news >正文

五星酒店网站建设方案学校的网站建设费如何入账

五星酒店网站建设方案,学校的网站建设费如何入账,二手车网站开发过程,vs 2017网站开发php目录 一、邻接矩阵表示法 二、AMGraph.h 三、AMGraph.c 四、Test.c 【数据结构第 6 章 ① 】- 图的定义和基本术语-CSDN博客 由于图的结构比较复杂#xff0c;任意两个顶点之间都可能存在联系#xff0c;因此无法以数据元素在存储区中的物理位置来表示元素之间的关系任意两个顶点之间都可能存在联系因此无法以数据元素在存储区中的物理位置来表示元素之间的关系即图没有顺序存储结构但可以借助二维数组来表示元素之间的关系即邻接矩阵表示法。另一方面由于图的任意两个顶点间都可能存在关系因此用链式存储表示图是很自然的事图的链式存储有多种有邻接表、十字链表和邻接多重表应根据实际需要的不同选择不同的存储结构。 一、邻接矩阵表示法 邻接矩阵Adjacency Matrix是表示顶点之间相邻关系的矩阵。设 G(V, E) 是具有 n 个顶点的图则 G 的邻接矩阵是具有如下性质的 n 阶方阵 例如图一中的 G1 和 G2 的邻接矩阵如下所示 若 G 是网则邻接矩阵可以定义为 其中  表示边上的权值​ 表示计算机允许的大于所有边上权值的数。例如下图所示为一个有向网和它的邻接矩阵。 二、AMGraph.h 用邻接矩阵表示法表示图除了一个用于存储邻接矩阵的二维数组外还需要用一个一维数组来存储顶点信息。 注意下面是以无向图为例的。 #pragma once#define DEFAULT_CAPACITY 10typedef char VertexType; // 假定顶点的数据类型为 char typedef int EdgeType; // 假定边的权值的数据类型为 inttypedef struct AMGraph {VertexType* vertices; // 顶点表vertices 是 vertex 的复数EdgeType** edges; // 邻接矩阵int vSize; // 当前图中的顶点数int eSize; // 当前图中的边数int capacity; // 容量 }AMGraph;// 基本操作 void AMGraphInit(AMGraph* pg); // 初始化void ShowAdjMatrix(AMGraph* pg); // 显示邻接矩阵int GetVetexPos(AMGraph* pg, VertexType v); // 获取顶点的位置void InsertVertex(AMGraph* pg, VertexType v); // 插入顶点 void InsertEdge(AMGraph* pg, VertexType v1, VertexType v2); // 插入边void EraseVertex(AMGraph* pg, VertexType v); // 删除顶点 void EraseEdge(AMGraph* pg, VertexType v1, VertexType v2); // 删除边int GetFirstAdjVexPos(AMGraph* pg, VertexType v); // 获取 v 的第一个邻接顶点的位置 int GetNextAdjVexPos(AMGraph* pg, VertexType v, VertexType w); // 获取 v 的相对于 w 的下一个邻接顶点的位置void AMGraphDestroy(AMGraph* pg); // 销毁 三、AMGraph.c 初始化 void AMGraphInit(AMGraph* pg) {assert(pg);pg-vSize pg-eSize 0;pg-capacity DEFAULT_CAPACITY;pg-vertices (VertexType*)malloc(sizeof(VertexType) * pg-capacity);assert(pg-vertices);pg-edges (EdgeType**)malloc(sizeof(EdgeType*) * pg-capacity);assert(pg-edges);for (int i 0; i pg-capacity; i){pg-edges[i] (EdgeType*)malloc(sizeof(EdgeType) * pg-capacity);assert(pg-edges[i]);for (int j 0; j pg-capacity; j){pg-edges[i][j] 0;}} } 获取顶点的位置 int GetVetexPos(AMGraph* pg, VertexType v) {assert(pg);for (int i 0; i pg-vSize; i){if (pg-vertices[i] v)return i;}return -1; } 显示邻接矩阵 void ShowAdjMatrix(AMGraph* pg) {assert(pg);printf( ); // 输出两个空格for (int i 0; i pg-vSize; i){printf(%c , pg-vertices[i]);}printf(\n);for (int i 0; i pg-vSize; i){printf(%c , pg-vertices[i]);for (int j 0; j pg-vSize; j){printf(%d , pg-edges[i][j]);}printf(\n);} } 插入顶点 void InsertVertex(AMGraph* pg, VertexType v) {assert(pg);// 考虑是否需要扩容if (pg-vSize pg-capacity){VertexType* tmp1 (VertexType*)realloc(pg-vertices, sizeof(VertexType) * 2 * pg-capacity);assert(tmp1);pg-vertices tmp1;EdgeType** tmp2 (EdgeType**)realloc(pg-edges, sizeof(EdgeType*) * 2 * pg-capacity);assert(tmp2);pg-edges tmp2;for (int i 0; i pg-capacity; i){EdgeType* tmp3 (EdgeType*)realloc(pg-edges[i], sizeof(EdgeType) * 2 * pg-capacity);assert(tmp3);pg-edges[i] tmp3;for (int j pg-capacity; j 2 * pg-capacity; j){pg-edges[i][j] 0;}}for (int i pg-capacity; i 2 * pg-capacity; i){pg-edges[i] (EdgeType*)malloc(sizeof(EdgeType) * 2 * pg-capacity);assert(pg-edges[i]);for (int j 0; j 2 * pg-capacity; j){pg-edges[i][j] 0;}}pg-capacity * 2;}// 插入顶点pg-vertices[pg-vSize] v; } 插入边 void InsertEdge(AMGraph* pg, VertexType v1, VertexType v2) {assert(pg);int pos1 GetVetexPos(pg, v1);int pos2 GetVetexPos(pg, v2);if (pos1 -1 || pos2 -1)return;if (pg-edges[pos1][pos2] ! 0)return;pg-edges[pos1][pos2] pg-edges[pos2][pos1] 1;pg-eSize; } 删除顶点 void EraseVertex(AMGraph* pg, VertexType v) {assert(pg);int pos GetVetexPos(pg, v);if (pos -1)return;// cnt 为和 v 相关联的边的数目int cnt 0;for (int j 0; j pg-vSize; j){if (pg-edges[pos][j] ! 0)cnt;}pg-vertices[pos] pg-vertices[pg-vSize - 1];for (int j 0; j pg-vSize; j){pg-edges[pos][j] pg-edges[pg-vSize - 1][j];}for (int i 0; i pg-vSize; i){pg-edges[i][pos] pg-edges[i][pg-vSize - 1];}--pg-vSize;pg-eSize - cnt; }删除边 void EraseEdge(AMGraph* pg, VertexType v1, VertexType v2) {assert(pg);int pos1 GetVetexPos(pg, v1);int pos2 GetVetexPos(pg, v2);if (pos1 -1 || pos2 -1)return;if (pg-edges[pos1][pos2] 0)return;pg-edges[pos1][pos2] pg-edges[pos2][pos1] 0;--pg-eSize; } 获取 v 的第一个邻接顶点 int GetFirstAdjVexPos(AMGraph* pg, VertexType v) {assert(pg);int pos GetVetexPos(pg, v);if (pos -1)return -1;for (int j 0; j pg-vSize; j){if (pg-edges[pos][j] ! 0)return j;}return -1; } 获取 v 的相对于 w 的下一个邻接顶点 int GetNextAdjVexPos(AMGraph* pg, VertexType v, VertexType w) {assert(pg);int pos1 GetVetexPos(pg, v);int pos2 GetVetexPos(pg, w);if (pos1 -1 || pos2 -1)return -1;for (int j pos2 1; j pg-vSize; j){if (pg-edges[pos1][j] ! 0)return j;}return -1; } 销毁 void AMGraphDestroy(AMGraph* pg) {assert(pg);free(pg-vertices);pg-vertices NULL;for (int i 0; i pg-capacity; i){free(pg-edges[i]);pg-edges[i] NULL;}free(pg-edges);pg-edges NULL;pg-vSize pg-eSize pg-capacity 0; } 四、Test.c #include AMGraph.h #include stdio.hint main() {AMGraph g;AMGraphInit(g); InsertVertex(g, A);InsertVertex(g, B);InsertVertex(g, C);InsertVertex(g, D);InsertVertex(g, E);InsertEdge(g, A, B);InsertEdge(g, A, D);InsertEdge(g, B, C);InsertEdge(g, B, E);InsertEdge(g, C, D);InsertEdge(g, C, E);ShowAdjMatrix(g);printf(\n);EraseVertex(g, C);ShowAdjMatrix(g);printf(\n);EraseEdge(g, A, B);ShowAdjMatrix(g);printf(\n);printf(%d\n, GetFirstAdjVexPos(g, A)); // 3printf(%d\n, GetNextAdjVexPos(g, A, D)); // -1AMGraphDestroy(g);return 0; }
http://www.zqtcl.cn/news/441498/

相关文章:

  • 公司在兰州要做网站怎样选择做期货关注什么网站
  • 响应式网站是指自适应吗新开传奇网站首区
  • 做网站产品介绍wordpress 参数 传递
  • 网站颜色搭配技巧建设摩托车价格大全
  • 哪些网站可以做画赚钱宁波模板建站定制
  • 昆明门户网站建设wordpress权限设置
  • 设计网站建设图片wordpress博客置顶
  • 网站上海网站建设网站数据建设涉及哪些内容
  • 3d效果图教程网站宁波网站建设慕枫科技
  • 视频结交网站怎么做想创建一个网站
  • 电商网站销售数据分析上海企业信息登记号查询
  • 网站建设规划设计公司排名无锡网站建设 君通科技
  • 徐州网站开发要多少钱给个人网站做百度百科
  • 法语网站建设免费网站为何收录比较慢
  • 品牌网站推广软件seo内链优化
  • 广东律师事务所东莞网站建设做网站 怎么备案
  • shopnc本地生活o2o网站源码wordpress文章内多页效果
  • 深圳全国网站制作哪个好页面设计有哪几种风格
  • 网页设计作业网站素材和效果图夏天做啥网站致富
  • 利用帝国软件如何做网站网站友链交换平台
  • 简述网站开发技术深圳网站设计合理刻
  • wordpress网站名称寻找销售团队外包
  • 一浪网站建设网页qq邮箱
  • 做网站需要注册公司吗夫唯seo系统培训
  • 沈阳人流哪个医院好安全百度关键词优化怎么做
  • 1688网站怎么做分销高质量的网站内容建设
  • 网站建设公司济宁网站转跳怎么做
  • 镇江网站设计多少钱企业网络部署方案
  • 建网站的公司浩森宇特wordpress登录缓存
  • 便宜建站空间战队头像在线制作免费