当前位置: 首页 > 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.pierceye.com/news/441498/

相关文章:

  • 上海 网站备案商务网站规划与建设课程设计
  • 网站 首页 栏目 内容网业设计
  • 用vs与dw做网站什么做电子书下载网站好
  • 网站建设发布教程网页设计师收费标准
  • 徐州哪里做网站好农林网站建设公司
  • 可以做直播卖产品的网站专业产品画册设计公司
  • wp网站开发个人小程序开发流程
  • 网站制作报价大约重庆招聘网站建设
  • 网站开发 资质网站开发价格评估
  • 泰州网站关键词优化谷歌建站
  • 门户网站风格企业网站建设的成本
  • 一站式外贸综合服务平台社区网站推广方案
  • 宁波网络公司网站建设项目怎么破解别人做的付费网站
  • 做创意小视频的网站centos 7.4 wordpress
  • 免费建立单位的网站适合个人做的跨境电商
  • 沈阳军成网站建设17网站一起做网店
  • 哪些cms做同城网站比较好上海建设工程协会网站
  • 潍坊企业自助建站系统seo博客网站
  • 做啤酒最全的网站鱼台县建设局网站
  • 网站开发转行进入衍生领域wordpress qaengine
  • 公司内部网站模板快速建网站的软件
  • 被骗去国外做网站网站推广网站的运营推广方案
  • 北京汽车业务网站开发公司桂林旅游攻略必去景点
  • 个人网站开发是学什么语言wordpress打造cms
  • 网站建设与维护的重要性岳阳建设厅网站
  • 惠州网站开发公司wordpress简单
  • 外贸网站 免费模板 使用 zencart如何购买域名和备案
  • 网站建设联系我们设计网站无锡
  • 深圳做网站好的公司wordpress建菜单
  • 网站编辑需要的技能做网站需要什么域名